Projet

Général

Profil

« Précédent | Suivant » 

Révision 589

Ajouté par gasacco il y a presque 4 ans

Affichage sur l'écran LCD en fonction des touches appuyées du clavier matricé (à améliorer)

Voir les différences:

SP4b1.c
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
/***********************************************************************/
#include "sfr32c87.h"
void init_keyboard(void);
void tpo_50ms(void);
unsigned char touche = 0;
unsigned char t =0;
void init_keyboard(void){
pd10 = 0x0F;
p10=0;
pu31 = 1;
}
void tpo_50ms(void){
tcspr = 0x8A;
ta0mr = 0x82;
ta0 = 50000;
ta0s = 1;
ta0os = 1;
ta0ic = 0x00;
while(ir_ta0ic != 1);
ta0s = 0;
}
#define LCD_DC p3_0
#define LCD_RW p3_1
#define LCD_E p3_2
#define LCD_DB4 p3_4
#define LCD_DB5 p3_5
#define LCD_DB6 p3_6
#define LCD_DB7 p3_7
void lcd_4b(unsigned char c)
{
LCD_E =1;
LCD_DB7 = (c & 0x80)>>7;
LCD_DB6 = (c & 0x40)>>6;
LCD_DB5 = (c & 0x20)>>5;
LCD_DB4 = (c & 0x10)>>4;
LCD_E =0;
}
void lcd_8b(unsigned char c)
{
lcd_4b(c);
lcd_4b(c<<4);
}
void lcd_com(char c)
{
LCD_DC =0;
lcd_8b(c);
}
void tpo_us(unsigned short duree) // temporisation en ?s
{
tcspr = 0x8A;
ta0mr = 0x82;
ta0 = duree;
ta0s = 1;
ta0os = 1;
ta0ic = 0x00;
while(ir_ta0ic != 1);
ta0s = 0;
}
void tpo_ms(unsigned short duree) // temporisation en ms
{
tpo_us(duree*1000);
}
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);
lcd_com(0x28);
lcd_com(0x06);
lcd_com(0x0E);
lcd_com(0x01);
tpo_ms(5);
}
void lcd_car(unsigned char c)
{
LCD_DC =1;
LCD_RW =0;
lcd_8b(c);
}
void lcd_str(unsigned char *str)
{
short i=0;
while (str[i] != '\0')
{
lcd_car(str[i]);
i++;
}
}
void main(void)
{
init_keyboard();
lcd_init();
pd3 =0xFF;
while(1)
{
p10 = 0x0B;
t = p10;
if (t == 0x7B)
{
lcd_com(0x01);
tpo_ms(10);
touche = '9';
lcd_car(touche);
}
else if (t==0xdB)
{
lcd_com(0x01);
tpo_ms(10);
touche = '8';
lcd_car(touche);
}
else if (t==0xeB)
{
lcd_com(0x01);
tpo_ms(10);
touche = '7';
lcd_car(touche);
}
p10 = 0x0E;
t = p10;
if (t==0xdE)
{
lcd_com(0x01);
tpo_ms(10);
touche = '2';
lcd_car(touche);
}
else if (t==0xbE)
{
lcd_com(0x01);
tpo_ms(10);
touche = '1';
lcd_car(touche);
}
else if (t==0x7E)
{
lcd_com(0x01);
tpo_ms(10);
touche = '3';
lcd_car(touche);
}
p10 = 0x0D;
t = p10;
if (t==0xdD)
{
lcd_com(0x01);
tpo_ms(10);
touche = '5';
lcd_car(touche);
}
else if (t==0xbD)
{
lcd_com(0x01);
tpo_ms(10);
touche = '4';
lcd_car(touche);
}
else if (t==0x7D)
{
lcd_com(0x01);
tpo_ms(10);
touche = '6';
lcd_car(touche);
}
}
}

Formats disponibles : Unified diff