Révision 591
Ajouté par jileng il y a plus de 4 ans
| SP4b2.c | ||
|---|---|---|
|
//importation bibliotheque
|
||
|
#include "sfr32c87.h"
|
||
|
|
||
|
void initPort1(void)
|
||
|
void initPort3(void);
|
||
|
|
||
|
void decodeChar(char c);
|
||
|
|
||
|
void decodeCharfaible(char c);
|
||
|
|
||
|
void Lcd4b(char c);
|
||
|
|
||
|
void Lcd8b(char c);
|
||
|
|
||
|
void LcdCom(char c);
|
||
|
|
||
|
void Lcd_init(void);
|
||
|
|
||
|
void LcdChar(char c);
|
||
|
|
||
|
void tpo_ms(int a) ;
|
||
|
|
||
|
void tpo_us(int a);
|
||
|
|
||
|
void main(void){
|
||
|
while(1){
|
||
|
pd1=0xff;
|
||
|
p1=0x00;
|
||
|
initPort3();
|
||
|
Lcd4b(0x00);
|
||
|
initPort3();
|
||
|
Lcd8b(0x35);
|
||
|
|
||
|
/*initPort3();
|
||
|
Lcd_init();
|
||
|
LcdChar('A');
|
||
|
LcdChar('test');
|
||
|
*/
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
void initPort3(void)
|
||
|
{
|
||
|
pd3=0xff;
|
||
|
p3=0x00;
|
||
|
pd1=0xff;
|
||
|
p1=0x00;
|
||
|
}
|
||
|
|
||
|
void decodeChar(char c){
|
||
|
//affectation valeur de c aux bits de data de 4 ? 7
|
||
|
if(c & 0x10){
|
||
|
p3_4=1;
|
||
|
p1_4=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_4=0;
|
||
|
else{
|
||
|
p1_4=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0x20){
|
||
|
p3_5=1;
|
||
|
p1_5=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_5=0;}
|
||
|
else{
|
||
|
p1_5=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0x80){
|
||
|
p3_6=1;
|
||
|
p1_6=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_6=0;
|
||
|
else{
|
||
|
p1_6=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0xf0){
|
||
|
p3_7=1;
|
||
|
p1_7=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_7=0;
|
||
|
else{
|
||
|
p1_7=0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void decodeCharF(char c){
|
||
|
void decodeCharfaible(char c){
|
||
|
if(c & 0x01){
|
||
|
p3_1=1;
|
||
|
p1_0=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_1=0;
|
||
|
else{
|
||
|
p1_0=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0x02){
|
||
|
p3_2=1;
|
||
|
p1_1=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_2=0;
|
||
|
else{
|
||
|
p1_1=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0x08){
|
||
|
p3_3=1;
|
||
|
p1_2=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_3=0;
|
||
|
else{
|
||
|
p1_2=0;
|
||
|
}
|
||
|
|
||
|
if(c & 0x0f){
|
||
|
p3_4=1;
|
||
|
p1_3=1;
|
||
|
}
|
||
|
else{
|
||
|
p3_4=0;
|
||
|
else{
|
||
|
p1_3=0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Lcd4b(char c){
|
||
|
p3_2=1;
|
||
|
p1_2=1;
|
||
|
decodeChar(c);
|
||
|
p3_2=0;
|
||
|
p1_2=0;
|
||
|
}
|
||
|
|
||
|
void Lcd8b(char c){
|
||
|
p3_2=1;
|
||
|
p1_2=1;
|
||
|
decodeChar(c);
|
||
|
decodeCharF(c);
|
||
|
p3_2=0;
|
||
|
decodeCharfaible(c);
|
||
|
p1_2=0;
|
||
|
}
|
||
|
|
||
|
void LcdCom(char c){
|
||
|
p3_0=0;
|
||
|
p1=0;
|
||
|
/*
|
||
|
//display on
|
||
|
p3_7=1;p3_6=1;p3_5=1;
|
||
|
//mode entree
|
||
|
p3=0;
|
||
|
p3_6=1;p3_5=1;
|
||
|
*/
|
||
|
//ecriture car
|
||
|
Lcd8b(c);
|
||
|
}
|
||
|
|
||
|
void Lcd_init(void)
|
||
|
{
|
||
|
p1_0=0;
|
||
|
tpo_ms(15);
|
||
|
Lcd4b(0x30);
|
||
|
tpo_ms(5);
|
||
|
Lcd4b(0x30);
|
||
|
tpo_us(100);
|
||
|
Lcd4b(0x30);
|
||
|
tpo_us(100);
|
||
|
Lcd4b(0x20);
|
||
|
LcdCom(0x28);
|
||
|
LcdCom(0x06);
|
||
|
LcdCom(0x0E);
|
||
|
LcdCom(0x01);
|
||
|
tpo_ms(5);
+
+
|
||
|
}
|
||
|
|
||
|
void LcdChar(char c){
|
||
|
p1_0=1;
|
||
|
Lcd8b(c);
|
||
|
}
|
||
|
|
||
|
void Lcd_init(void){
|
||
|
Lcd4b();
|
||
|
LcdCom();
|
||
|
/*
|
||
|
void tpo_ms(int a){
|
||
|
tcspr = 0x8A;
|
||
|
ta0mr = 0x82;
|
||
|
ta0 = a*1000;
|
||
|
ta0s = 1;ta0os = 1;
|
||
|
ta0ic = 0x00;
|
||
|
while(ir_ta0ic != 1);
|
||
|
ta0s = 0;
|
||
|
}
|
||
|
|
||
|
void LcdChar(char c){
|
||
|
p3_0=1;
|
||
|
Lcd4b(c);
|
||
|
void tpo_us(int a){
|
||
|
tcspr = 0x8A;
|
||
|
ta0mr = 0x82;
|
||
|
ta0 = a;
|
||
|
ta0s = 1;ta0os = 1;
|
||
|
ta0ic = 0x00;
|
||
|
while(ir_ta0ic != 1);
|
||
|
ta0s = 0;
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
|
||
|
|
||
|
void main(void)
|
||
|
{
|
||
|
while(1){
|
||
|
pd3=0xff;
|
||
|
p3=0xff;
|
||
|
initPort1();
|
||
|
Lcd4b(0x00);
|
||
|
initPort1();
|
||
|
Lcd8b(0x00);
|
||
|
initPort1();
|
||
|
Lcd_init();
|
||
|
LcdChar(0x00);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
Formats disponibles : Unified diff
commit leng Sp4b2.hsf .ini .c modification fonction lcd8b et ajout Lcd_init