Révision 697
Ajouté par anclaud il y a presque 4 ans
SP4b2.c | ||
---|---|---|
#define LCD_RW_DIR LCD_PORT_DIR
|
||
#define LCD_DC_DIR LCD_PORT_DIR
|
||
|
||
void tpo_us(unsigned short duree);// temporisation en ?s
|
||
void tpo_ms(unsigned short duree);// temporisation en ms
|
||
void lcd_init_port(void); // initialisation des broches du ?C
|
||
void lcd_4b(unsigned char car); // envoi des 4 bits de poids fort
|
||
void lcd_8b(unsigned char car); // envoi des 8 bits de donn?e
|
||
void lcd_car(unsigned char car);// envoi d'une donn?e ? afficher
|
||
void lcd_com(unsigned char com);// envoi d'une commande
|
||
void lcd_init(void); // initialisation de l'afficheur
|
||
void lcd_str(unsigned char *str); // envoi d'une cha?ne de caract?re
|
||
void tpo_us(unsigned short duree); // temporisation en ?s
|
||
void tpo_ms(unsigned short duree); // temporisation en ms
|
||
void lcd_init_port(void); // initialisation des broches du ?C
|
||
void lcd_4b(unsigned char car); // envoi des 4 bits de poids fort
|
||
void lcd_8b(unsigned char car); // envoi des 8 bits de donn?e
|
||
void lcd_car(unsigned char car); // envoi d'une donn?e ? afficher
|
||
void lcd_com(unsigned char com); // envoi d'une commande
|
||
void lcd_init(void); // initialisation de l'afficheur
|
||
void lcd_str(unsigned char *str); // envoi d'une cha?ne de caract?re
|
||
|
||
void init_keyboard(void); // initialisation du clavier
|
||
void keyboard(void); // detection des touches du clavier
|
||
void affichage_keyboard(unsigned char *str); // Affichage sur l'ecran
|
||
|
||
void lcd_4b(unsigned char car)
|
||
{
|
||
... | ... | |
{
|
||
LCD_DB4 = 0;
|
||
}
|
||
|
||
tpo_us(1);
|
||
LCD_E = 0;
|
||
tpo_us(1);
|
||
}
|
||
void lcd_8b(unsigned char car)
|
||
{
|
||
... | ... | |
while(ir_ta0ic != 1);
|
||
ta0s = 0;
|
||
}
|
||
|
||
void tpo_50ms(void)
|
||
{
|
||
tcspr = 0x8A;
|
||
ta0mr = 0x82;
|
||
ta0 = 50000;
|
||
ta0s = 1;
|
||
ta0os = 1;
|
||
ta0ic = 0x00;
|
||
while(ir_ta0ic != 1);
|
||
ta0s = 0;
|
||
}
|
||
|
||
// initialize the LCD display
|
||
void lcd_init(void)
|
||
{
|
||
pd3=0xFF; //Initialisation en sortie
|
||
LCD_DC=0;
|
||
tpo_ms(15);
|
||
lcd_4b(0x30);
|
||
... | ... | |
tpo_ms(5);
|
||
}
|
||
|
||
void init_keyboard(void)
|
||
{
|
||
pd10 = 0x0F;
|
||
p10 = 0;
|
||
pu31 = 1;
|
||
}
|
||
|
||
void keyboard(void)
|
||
{
|
||
unsigned char t;
|
||
p10=0xf7;
|
||
t=p10;
|
||
if (t==0xe7)
|
||
{
|
||
affichage_keyboard("*");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0xd7)
|
||
{
|
||
affichage_keyboard("0");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0x77)
|
||
{
|
||
affichage_keyboard("#");
|
||
tpo_ms(50);
|
||
}
|
||
|
||
p10=0xfb;
|
||
t=p10;
|
||
|
||
if (t==0xeb)
|
||
{
|
||
affichage_keyboard("7");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0xdb)
|
||
{
|
||
affichage_keyboard("8");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0x7b)
|
||
{
|
||
affichage_keyboard("9");
|
||
tpo_ms(50);
|
||
}
|
||
|
||
p10=0xfd;
|
||
t=p10;
|
||
if (t==0xbd)
|
||
{
|
||
affichage_keyboard("4");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0xdd)
|
||
{
|
||
affichage_keyboard("5");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0x7d)
|
||
{
|
||
affichage_keyboard("6");
|
||
tpo_ms(50);
|
||
}
|
||
|
||
p10=0xfe;
|
||
t=p10;
|
||
if (t==0xbe)
|
||
{
|
||
affichage_keyboard("1");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0xde)
|
||
{
|
||
affichage_keyboard("2");
|
||
tpo_ms(50);
|
||
}
|
||
if (t==0x7e)
|
||
{
|
||
affichage_keyboard("3");
|
||
tpo_ms(50);
|
||
}
|
||
}
|
||
|
||
void affichage_keyboard(unsigned char *str)
|
||
{
|
||
//lcd_com(0x01); // Pour afficher un seul chiffre a chaque fois
|
||
tpo_ms(50);
|
||
lcd_str(str);
|
||
}
|
||
|
||
void main(void)
|
||
{
|
||
pd3=0xFF; //Initialisation en sortie
|
||
char t;
|
||
lcd_init();
|
||
//lcd_car('A');
|
||
//lcd_4b(0xFF);
|
||
//lcd_4b(0xA0);
|
||
//lcd_8b(0xAB);
|
||
lcd_str("Antonin CLAUD");
|
||
init_keyboard();
|
||
while(1)
|
||
{
|
||
t = p10;
|
||
|
||
if (t != 0xf0){
|
||
keyboard();
|
||
}
|
||
}
|
||
//lcd_str("Antonin CLAUD");
|
||
}
|
||
|
Formats disponibles : Unified diff
Clavier + Afficheur LCD connecté fonctionnel