Projet

Général

Profil

« Précédent | Suivant » 

Révision 594

Ajouté par abseck1 il y a presque 4 ans

suite TP2B

Voir les différences:

SP4b2.c
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
/***********************************************************************/
#define LCD_E
#define LCD_RW
#define LCD_DC
#define LCD_E_DIR
#define LCD_RW_DIR
#include "sfr32c87.h"
#define RS p1_0
#define RW p1_1
#define E p1_2
#define BF p0_7
void tpo_us(unsigned short duree);
void tpo_ms(unsigned short duree);
void lcd_init_port(void);
void lcd_4b(unsigned char car);
void lcd_8b(unsigned char car);
void lcd_car(unsigned char car);
void lcd_com(unsigned char com);
void lcd_unit(void);
void lcd_str(unsigned char *str);
void tempo(void)
{
int i;
for (i=0 ; i<1000 ;i++)
asm("nop");
void lcd_4b(unsigned char car)
{
p1_2=1;
if (car & 0x80)
p1_7=1;
else p1_7=0;
if (car & 0x40)
p1_6=1;
else p1_6=0;
if (car & 0x20)
p1_5=1;
else p1_5=0;
if (car & 0x10)
p1_4=1;
else p1_4=0;
p1_2=0;
}
void init_ports_aff(void)
void lcd_8b(unsigned char car)
{
pd0 = 0xff;
p0 = 0x00;
pd1= 0xff;
p1=0x00;
lcd_4b(car);
lcd_4b(car<<4);
}
void busy(void)
void lcd_com(unsigned char c)
{
pd0=0x00;//entr?e
RS=0;
RW=1;
E=1;
while(BF!=0);
E=0;
pd0=0xff;//sortie
p1_0=0;
lcd_8b(c);
}
void affiche_caractere(unsigned char caractere)
void lcd_car(unsigned char car)
{
p1_0=1;
lcd_8b(car);
}
void lcd_4b(unsigned char car)
{
p3_2=1;
if (car & 0x80)
p3_7=1;
else p1_7=0;
if (car & 0x40)
p3_6=1;
else p1_6=0;
if (car & 0x20)
p3_5=1;
else p1_5=0;
if (car & 0x10)
p3_4=1;
else p1_4=0;
p3_2=0;
RS=1;
RW=0;
p0=caractere;
E=1;
tempo();
E=0;
tempo();
busy();
}
void affiche_commande(unsigned char commande)
void lcd_8b(unsigned char car)
{
lcd_4b(car);
lcd_4b(car<<4);
}
RS=0;
RW=0;
p0=commande;
E=1;
tempo();
E=0;
tempo();
busy();
void lcd_com(unsigned char c)
{
p3_0=0;
lcd_8b(c);
}
void lcd_car(unsigned char car)
{
p3_0=1;
lcd_8b(car);
}
void lcd_str(unsigned char *str){
int i=0;
while(str[i]='\0')
str([i]!='\0';
{
lcd_car(str[i]);
i++;
}
}
void tpo_ms(unsigned short duree){
tcspr = 0x8A;
ta0mr = 0x82;
ta0 = duree*1000;
ta0s = 1;
ta0os = 1;
ta0ic = 0x00;
while(ir_ta0ic != 1);
ta0s = 0;
}
void tpo_us(unsigned short duree){
tcspr = 0x8A;
ta0mr = 0x82;
ta0 = duree;
ta0s = 1;
ta0os = 1;
ta0ic = 0x00;
while(ir_ta0ic != 1);
ta0s = 0;
}
void lcd_init(void){
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 main(void)
{
unsigned char c[]="Bonjour";
pd3=0xff;
lcd_4b(c);
lcd_8b(c);
lcd_init();
lcd_str(c);
}

Formats disponibles : Unified diff