root/branch/sabot/sp4abc/sp4b1/SP4b1/SP4b1.c @ 487
384 | chsabot | /***********************************************************************/
|
|
/* */
|
|||
/* FILE :SP4b1.c */
|
|||
/* DATE :Thu, May 20, 2021 */
|
|||
/* DESCRIPTION :main program file. */
|
|||
/* CPU GROUP :87 */
|
|||
/* */
|
|||
/* This file is generated by Renesas Project Generator (Ver.4.18). */
|
|||
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
|||
/***********************************************************************/
|
|||
402 | chsabot | #include "sfr32c87.h"
|
|
487 | chsabot | #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
|
|||
402 | chsabot | ||
477 | chsabot | ||
//temporisation en us
|
|||
487 | chsabot | void tpo_us(unsigned short duree){
|
|
tcspr = 0x8A;
|
|||
ta0mr = 0x82;
|
|||
ta0 = duree;
|
|||
ta0s = 1;ta0os = 1;
|
|||
ta0ic = 0x00;
|
|||
while(ir_ta0ic != 1);
|
|||
ta0s = 0;
|
|||
}
|
|||
477 | chsabot | ||
// temporisation en ms
|
|||
487 | chsabot | void tpo_ms(unsigned short duree){
|
|
tpo_us(duree*1000);
|
|||
}
|
|||
477 | chsabot | ||
//envoie des 4 bits de poids fort
|
|||
void lcd_4b(unsigned char car){
|
|||
487 | chsabot | LCD_E=1;
|
|
pd3=0xff;
|
|||
477 | chsabot | if (car & 16){
|
|
487 | chsabot | LCD_PORT4=1;
|
|
477 | chsabot | }
|
|
else{
|
|||
487 | chsabot | LCD_PORT4=0;
|
|
477 | chsabot | }
|
|
if (car & 32){
|
|||
487 | chsabot | LCD_PORT5=1;
|
|
477 | chsabot | }
|
|
else{
|
|||
487 | chsabot | LCD_PORT5=0;
|
|
477 | chsabot | }
|
|
if (car & 64){
|
|||
487 | chsabot | LCD_PORT6=1;
|
|
477 | chsabot | }
|
|
else{
|
|||
487 | chsabot | LCD_PORT6=0;
|
|
477 | chsabot | }
|
|
487 | chsabot | 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);
|
|||
477 | chsabot | ||
384 | chsabot | }
|
|
487 | chsabot | //envoi d'une commande
|
|
void lcd_com(unsigned char com){
|
|||
LCD_DC=0;
|
|||
lcd_8b(com);
|
|||
402 | chsabot | ||
477 | chsabot | }
|
|
402 | chsabot | ||
487 | chsabot | //envoie d'une donn?e ? l'afficheur
|
|
void lcd_car(unsigned char car){
|
|||
LCD_DC=1;
|
|||
lcd_8b(car);
|
|||
}
|
|||
477 | chsabot | ||
487 | chsabot | //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;
|
|||
}
|
|||
}
|
|||
477 | chsabot | //void main(void){
|
|
487 | chsabot | // pd3=0xff;
|
|
// lcd_init();
|
|||
// lcd_4b(0xf0);
|
|||
// lcd_8b(0x28);
|
|||
// lcd_car('a');
|
|||
// lcd_car('b');
|
|||
// lcd_str("salut");
|
|||
477 | chsabot | //}
|
|
487 | chsabot | //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';
|
|||
}
|
|||
}
|
|||
}
|
|||
}
|
|||