|
/***********************************************************************/
|
|
/* */
|
|
/* FILE :Sp4b2.c */
|
|
/* DATE :Tue, May 25, 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. */
|
|
/***********************************************************************/
|
|
#include"sfr32c87.h"
|
|
#include <stdlib.h>
|
|
|
|
void lcd_4b(unsigned char car);
|
|
void lcd_8b(unsigned char car);
|
|
void lcd_com(unsigned char car);
|
|
void lcd_char(unsigned char car);
|
|
void lcd_init(void);
|
|
void tpo_us(unsigned short duree);
|
|
void tpo_ms(unsigned short duree);
|
|
void lcd_str(unsigned char * str);
|
|
char touche(void);
|
|
void affiche_touche(void);
|
|
//void add(void);
|
|
int decode_int(char c);
|
|
void multiple_touche(int n);
|
|
|
|
void main(void){
|
|
char t;
|
|
pd3 = 0xff;
|
|
pd10 = 0x0f;
|
|
lcd_init();
|
|
multiple_touche(50);
|
|
// add();
|
|
|
|
}
|
|
|
|
void lcd_4b(unsigned char car){
|
|
|
|
p3_2 = 1;
|
|
|
|
if(car & 0x10){
|
|
p3_4 = 1;
|
|
}
|
|
else{
|
|
p3_4 = 0;
|
|
}
|
|
|
|
if(car & 0x20){
|
|
p3_5 = 1;
|
|
}
|
|
else{
|
|
p3_5 = 0;
|
|
}
|
|
|
|
if(car & 0x40){
|
|
p3_6 = 1;
|
|
}
|
|
else{
|
|
p3_6 = 0;
|
|
}
|
|
if(car & 0x80){
|
|
p3_7 = 1;
|
|
}
|
|
else{
|
|
p3_7 = 0;
|
|
}
|
|
|
|
|
|
p3_2 = 0;
|
|
}
|
|
|
|
void lcd_8b(unsigned char car){
|
|
lcd_4b(car);
|
|
lcd_4b(car << 4);
|
|
|
|
}
|
|
|
|
void lcd_com(unsigned char car){
|
|
p3_0 = 0;
|
|
lcd_8b(car);
|
|
}
|
|
|
|
void lcd_char(unsigned char car){
|
|
p3_0 = 1;
|
|
lcd_8b(car);
|
|
}
|
|
|
|
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 tpo_ms(unsigned short duree){
|
|
tpo_us(duree*1000);
|
|
}
|
|
|
|
void lcd_str(unsigned char * str){
|
|
|
|
char tmp;
|
|
int i=0;
|
|
tmp = str[0];
|
|
while(tmp != '\0'){
|
|
lcd_char(tmp);
|
|
i=i+1;
|
|
tmp = str[i];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
char touche(void){
|
|
char touche;
|
|
char t;
|
|
pu31 = 1;
|
|
p10 = 0x00;
|
|
while(1){
|
|
t=p10;
|
|
if(t!= 0xF0){
|
|
p10 =0xFE;
|
|
t=p10;
|
|
if(t==0xDE){
|
|
touche ='2';
|
|
return touche;
|
|
}
|
|
if(t==0x7E){
|
|
touche ='3';
|
|
return touche;
|
|
}
|
|
if(t==0xBE){
|
|
touche ='1';
|
|
return touche;
|
|
}
|
|
p10 =0xFD;
|
|
t=p10;
|
|
if(t==0xDD){
|
|
touche ='5';
|
|
return touche;
|
|
}
|
|
if(t==0x7D){
|
|
touche ='6';
|
|
return touche;
|
|
}
|
|
if(t==0xBD){
|
|
touche ='4';
|
|
return touche;
|
|
}
|
|
p10 =0xFB;
|
|
t=p10;
|
|
if(t==0xDB){
|
|
touche ='8';
|
|
return touche;
|
|
}
|
|
if(t==0x7B){
|
|
touche ='9';
|
|
return touche;
|
|
}
|
|
if(t==0xEB){
|
|
touche ='7';
|
|
return touche;
|
|
}
|
|
p10 =0xF7;
|
|
t=p10;
|
|
if(t==0xE7){
|
|
touche ='*';
|
|
return touche;
|
|
}
|
|
if(t==0x77){
|
|
touche ='#';
|
|
return touche;
|
|
}
|
|
if(t==0xD7){
|
|
touche ='0';
|
|
return touche;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void affiche_touche(void){
|
|
char a;
|
|
a = touche();
|
|
lcd_char(a);
|
|
}
|
|
|
|
|
|
void multiple_touche(int n){
|
|
int i;
|
|
for(i=0;i<n;i++){
|
|
affiche_touche();
|
|
tpo_ms(500);
|
|
tpo_ms(500);
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int decode_int(char c)
|
|
{
|
|
|
|
int resultat= c-48;
|
|
if (resultat>-1 && resultat<10){
|
|
return resultat;
|
|
}
|
|
else return -1;
|
|
|
|
|
|
}
|
|
|
|
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(0x0F);
|
|
lcd_com(0x01);
|
|
tpo_ms(5);
|
|
}
|