Révision 487
Ajouté par chsabot il y a presque 4 ans
SP4b1.c | ||
---|---|---|
|
||
#include "sfr32c87.h"
|
||
|
||
#define LCD_E()
|
||
#define LCD_E_DIR()
|
||
#define LCD_E p3_2
|
||
#define LCD_RW p3_1
|
||
#define LCD_DC p3_0
|
||
#define LCD_PORT4 p3_4
|
||
#define LCD_PORT5 p3_5
|
||
#define LCD_PORT6 p3_6
|
||
#define LCD_PORT7 p3_7
|
||
|
||
#define LCD_RW()
|
||
#define LCD_RW_DIR()
|
||
|
||
#define LCD_DC()
|
||
#define LCD_DC_DIR()
|
||
|
||
#define LCD_PORT()
|
||
#define LCD_PORT_DIR()
|
||
|
||
//temporisation en us
|
||
void tpo_us(unsigned short duree);
|
||
void tpo_us(unsigned short duree){
|
||
tcspr = 0x8A;
|
||
ta0mr = 0x82;
|
||
ta0 = duree;
|
||
ta0s = 1;ta0os = 1;
|
||
ta0ic = 0x00;
|
||
while(ir_ta0ic != 1);
|
||
ta0s = 0;
|
||
}
|
||
|
||
// temporisation en ms
|
||
void tpo_ms(unsigned short duree);
|
||
void tpo_ms(unsigned short duree){
|
||
tpo_us(duree*1000);
|
||
}
|
||
|
||
|
||
//envoie des 4 bits de poids fort
|
||
void lcd_4b(unsigned char car){
|
||
p1_2=1;
|
||
p1_2=0;
|
||
car=3;
|
||
if (car & 8){
|
||
p1_4=1;
|
||
}
|
||
else{
|
||
p1_4=0;
|
||
}
|
||
LCD_E=1;
|
||
pd3=0xff;
|
||
if (car & 16){
|
||
p1_5=1;
|
||
LCD_PORT4=1;
|
||
}
|
||
else{
|
||
p1_5=0;
|
||
LCD_PORT4=0;
|
||
}
|
||
if (car & 32){
|
||
p1_6=1;
|
||
LCD_PORT5=1;
|
||
}
|
||
else{
|
||
p1_6=0;
|
||
LCD_PORT5=0;
|
||
}
|
||
if (car & 64){
|
||
p1_7=1;
|
||
LCD_PORT6=1;
|
||
}
|
||
else{
|
||
p1_7=0;
|
||
LCD_PORT6=0;
|
||
}
|
||
if (car & 128){
|
||
LCD_PORT7=1;
|
||
}
|
||
else{
|
||
LCD_PORT7=0;
|
||
}
|
||
LCD_E=0;
|
||
}
|
||
|
||
// envoie des 8 bits de donn?e
|
||
void lcd_8b(unsigned char car){
|
||
lcd_4b(car);
|
||
lcd_4b(car<<4);
|
||
|
||
}
|
||
//envoi d'une commande
|
||
void lcd_com(unsigned char com){
|
||
LCD_DC=0;
|
||
lcd_8b(com);
|
||
|
||
void main(void){
|
||
lcd_4b(0xF0);
|
||
}
|
||
|
||
//envoie d'une donn?e ? l'afficheur
|
||
void lcd_car(unsigned char car){
|
||
LCD_DC=1;
|
||
lcd_8b(car);
|
||
}
|
||
|
||
//Clavier
|
||
//char t;
|
||
//char touche;
|
||
//initialisation de l'afficheur
|
||
void lcd_init(void){
|
||
LCD_DC=0;
|
||
tpo_ms(15);
|
||
lcd_4b(0x30);
|
||
tpo_ms(5);
|
||
lcd_4b(0x30);
|
||
tpo_us(100);
|
||
lcd_4b(0x30);
|
||
tpo_us(100);
|
||
lcd_4b(0x20);//on ecrit juste une fois(pas 2 segments)
|
||
lcd_com(0x28);//mode 2 lignes
|
||
lcd_com(0x06);//incrementation du curseur
|
||
lcd_com(0x0E);//Ecran allum? + curseur
|
||
lcd_com(0x01);//effacer
|
||
tpo_ms(5);
|
||
}
|
||
|
||
//envoi d'une chaine de carateres
|
||
void lcd_str(unsigned char *str){
|
||
int i=0;
|
||
while(str[i]!='\0'){
|
||
lcd_car(str[i]);
|
||
i=i+1;
|
||
}
|
||
}
|
||
|
||
|
||
//void main(void){
|
||
|
||
// pd10=0x0F;
|
||
// pu31=1;
|
||
// p10=0x00;
|
||
// while(1){
|
||
// t=p10;
|
||
// if(t!=0xF0){
|
||
// p10=0xFE;
|
||
// t=p10;
|
||
// if(t==0xDE){
|
||
// touche='2';
|
||
// }
|
||
// if(t==0x7E){
|
||
// touche='3';
|
||
// }
|
||
// if(t==0xBE){
|
||
// touche='1';
|
||
// }
|
||
// p10=0xFD;
|
||
// t=p10;
|
||
// if(t==0x7D){
|
||
// touche='6';
|
||
// }
|
||
// if(t==0xDD){
|
||
// touche='5';
|
||
// }
|
||
// if(t==0xBD){
|
||
// touche='4';
|
||
// }
|
||
//
|
||
// }
|
||
// }
|
||
// pd3=0xff;
|
||
// lcd_init();
|
||
// lcd_4b(0xf0);
|
||
// lcd_8b(0x28);
|
||
// lcd_car('a');
|
||
// lcd_car('b');
|
||
// lcd_str("salut");
|
||
//}
|
||
|
||
|
||
//Clavier
|
||
char t;
|
||
char touche;
|
||
void main(void){
|
||
|
||
pd10=0x0F;
|
||
pu31=1;
|
||
p10=0x00;
|
||
pd3=0xff;
|
||
lcd_init();
|
||
while(1){
|
||
t=p10;
|
||
if(t!=0xF0){
|
||
p10=0xFE;
|
||
t=p10;
|
||
if(t==0xDE){
|
||
touche='2';
|
||
lcd_car(touche);
|
||
}
|
||
if(t==0x7E){
|
||
touche='3';
|
||
lcd_car(touche);
|
||
}
|
||
if(t==0xBE){
|
||
touche='1';
|
||
}
|
||
p10=0xFD;
|
||
t=p10;
|
||
if(t==0x7D){
|
||
touche='6';
|
||
}
|
||
if(t==0xDD){
|
||
touche='5';
|
||
}
|
||
if(t==0xBD){
|
||
touche='4';
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
|
Formats disponibles : Unified diff
modification afficheur