Révision 707
Ajouté par Abdou FAYE il y a presque 4 ans
SP4b2.c | ||
---|---|---|
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
||
/***********************************************************************/
|
||
|
||
#include "sfr32c87.h"
|
||
#include "sfr32c87.h"
|
||
|
||
|
||
|
||
void lcd_4b(unsigned char car); // envoi des 4 bits de poids fort
|
||
void lcd_8b(unsigned char car); // envoi des 8 bits de poids fort
|
||
void lcd_4b (char c);
|
||
void lcd_8b (char c);
|
||
void lcd_com (char c);
|
||
void lcd_init (void);
|
||
void lcd_car (char c);
|
||
void tpo_ms(int t);
|
||
void tpo_us(int t);
|
||
|
||
void main(void)
|
||
{
|
||
pd1 = 0xFF;
|
||
while (1)
|
||
{
|
||
lcd_4b(0x30);
|
||
lcd_8b(0x3F);
|
||
}
|
||
}
|
||
void lcd_4b (char c)
|
||
{
|
||
p3_2=1;
|
||
|
||
if (c&0x80)
|
||
{
|
||
p3_7=1;
|
||
}
|
||
else
|
||
p3_7 = 0;
|
||
|
||
if (c&0x40)
|
||
{
|
||
p3_6=1;
|
||
}
|
||
else
|
||
p3_6 = 0;
|
||
|
||
if (c&0x20)
|
||
{
|
||
p3_5=1;
|
||
}
|
||
else
|
||
p3_5 = 0;
|
||
|
||
if (c&0x10)
|
||
{
|
||
p3_4=1;
|
||
}
|
||
else
|
||
p3_4 = 0;
|
||
|
||
|
||
p3_2=0;
|
||
|
||
}
|
||
void lcd_8b (char c)
|
||
{
|
||
lcd_4b (c);
|
||
lcd_4b (c<<4);
|
||
}
|
||
|
||
|
||
/*void lcd_8b(unsigned char car); // envoi des 8 bits de poids fort
|
||
void lcd_com(char c)
|
||
{
|
||
p3_0=0;
|
||
lcd_8b(c);
|
||
}
|
||
|
||
{
|
||
lcd_4b(car<<4);
|
||
lcd_4b(car>>4);
|
||
}*/
|
||
void lcd_4b(unsigned char car)
|
||
{
|
||
pd1 =0xFF;
|
||
p1_2 = 0; // E = 1
|
||
if(car&0x80)
|
||
{
|
||
p1_7 = 1;
|
||
}
|
||
else
|
||
{
|
||
p1_7 = 0;
|
||
}
|
||
if(car&0x40)
|
||
{
|
||
p1_6 = 1;
|
||
}
|
||
else
|
||
{
|
||
p1_6 = 0;
|
||
}
|
||
if(car&0x10)
|
||
{
|
||
p1_5 = 1;
|
||
}
|
||
else
|
||
{
|
||
p1_5 = 0;
|
||
}
|
||
if(car&0x01)
|
||
{
|
||
p1_4 = 1;
|
||
}
|
||
else
|
||
{
|
||
p1_4 = 0;
|
||
}
|
||
void tpo_ms(int t)
|
||
{
|
||
tcspr = 0x8a;
|
||
ta0mr = 0x82;
|
||
ta0=t*1000;
|
||
ta0s = 1;
|
||
ta0os=1;
|
||
ta0ic=0x00;
|
||
while (ir_ta0ic!=1);
|
||
ta0s=0;
|
||
}
|
||
|
||
void tpo_us(int t)
|
||
{
|
||
tcspr = 0x8a;
|
||
ta0mr = 0x82;
|
||
ta0=t;
|
||
ta0s = 1;
|
||
ta0os=1;
|
||
ta0ic=0x00;
|
||
while (ir_ta0ic!=1);
|
||
ta0s=0;
|
||
}
|
||
|
||
void lcd_init (void)
|
||
{
|
||
|
||
pd3=0xFF;
|
||
p3 = 0;
|
||
p3_0=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 (char c)
|
||
{
|
||
p3_0=1;
|
||
lcd_8b(c);
|
||
}
|
||
|
||
char decode_touche(char t){
|
||
char t;
|
||
char touche;
|
||
pd10= 0x0F;
|
||
pu31=1;
|
||
p10=0x00;
|
||
p10= 0xFe;
|
||
t=p10;
|
||
|
||
if (t==0xde){
|
||
touche ='2';
|
||
}
|
||
|
||
if (t==0xbe){
|
||
touche ='1';
|
||
}
|
||
if (t==0x7e){
|
||
touche ='3';
|
||
}
|
||
|
||
p10= 0xFd;
|
||
t=p10;
|
||
if (t==0xdd){
|
||
touche ='5';
|
||
}
|
||
|
||
if (t==0xbd){
|
||
touche ='4';
|
||
}
|
||
|
||
|
||
if (t==0x7d){
|
||
touche ='6';
|
||
}
|
||
|
||
p10= 0xFb;
|
||
t=p10;
|
||
if (t==0xdb){
|
||
touche ='8';
|
||
}
|
||
|
||
if (t==0xeb){
|
||
touche ='7';
|
||
}
|
||
|
||
if (t==0x7b){
|
||
touche ='9';
|
||
}
|
||
|
||
p10= 0xF7;
|
||
t=p10;
|
||
|
||
if (t==0xd7){
|
||
touche ='0';
|
||
}
|
||
|
||
if (t==0x77){
|
||
touche ='#';
|
||
}
|
||
|
||
if (t==0xe7){
|
||
touche ='*';
|
||
}
|
||
return touche;
|
||
|
||
}
|
||
|
||
|
||
void main(void){
|
||
char t;
|
||
t=p10;
|
||
|
||
lcd_init ();
|
||
|
||
|
||
|
||
while(1){
|
||
/*if(p10!=0xf0){
|
||
p10=0x00;*/
|
||
lcd_car ('A');
|
||
|
||
/*while(p10!=0xf0){
|
||
p10=0x00;
|
||
}*/
|
||
}
|
||
|
||
}
|
||
|
||
|
||
|
Formats disponibles : Unified diff
finir le TP2b