Projet

Général

Profil

470 ahkurklu
/***********************************************************************/
/* */
/* 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. */
/***********************************************************************/
475 ahkurklu
#include"sfr32c87.h"
480 ahkurklu
#include <stdlib.h>
475 ahkurklu
void lcd_4b(unsigned char car);
478 ahkurklu
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);
480 ahkurklu
char touche(void);
void affiche_touche(void);
//void add(void);
int decode_int(char c);
475 ahkurklu
void main(void){
480 ahkurklu
char t;
478 ahkurklu
pd3 = 0xff;
480 ahkurklu
pd10 = 0x0f;
478 ahkurklu
lcd_init();
480 ahkurklu
// affiche_touche();
add();

475 ahkurklu
}
470 ahkurklu
475 ahkurklu
void lcd_4b(unsigned char car){
470 ahkurklu
478 ahkurklu
p3_2 = 1;
480 ahkurklu
475 ahkurklu
if(car & 0x10){
478 ahkurklu
p3_4 = 1;
475 ahkurklu
}
else{
478 ahkurklu
p3_4 = 0;
475 ahkurklu
}

if(car & 0x20){
478 ahkurklu
p3_5 = 1;
475 ahkurklu
}
else{
478 ahkurklu
p3_5 = 0;
475 ahkurklu
}

if(car & 0x40){
478 ahkurklu
p3_6 = 1;
475 ahkurklu
}
else{
478 ahkurklu
p3_6 = 0;
475 ahkurklu
}
if(car & 0x80){
478 ahkurklu
p3_7 = 1;
475 ahkurklu
}
else{
478 ahkurklu
p3_7 = 0;
475 ahkurklu
}


478 ahkurklu
p3_2 = 0;
470 ahkurklu
}
475 ahkurklu
478 ahkurklu
void lcd_8b(unsigned char car){
lcd_4b(car);
lcd_4b(car << 4);

}
475 ahkurklu
478 ahkurklu
void lcd_com(unsigned char car){
p3_0 = 0;
lcd_8b(car);
}
475 ahkurklu
478 ahkurklu
void lcd_char(unsigned char car){
p3_0 = 1;
lcd_8b(car);
}
475 ahkurklu
478 ahkurklu
void tpo_us(unsigned short duree){
tcspr = 0x8A;
ta0mr = 0x82;
ta0 = duree;
ta0s = 1; ta0os = 1;
ta0ic = 0x00;
while(ir_ta0ic != 1);
ta0s = 0;
}
475 ahkurklu
478 ahkurklu
void tpo_ms(unsigned short duree){
tpo_us(duree*1000);
}

void lcd_str(unsigned char * str){
479 ahkurklu
char tmp;
int i=0;
tmp = str[0];
while(tmp != '\0'){
lcd_char(tmp);
i=i+1;
tmp = str[i];
}
478 ahkurklu
}


480 ahkurklu
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;
exit(1);
}
if(t==0x7E){
touche ='3';
return touche;
exit(1);
}
if(t==0xBE){
touche ='1';
return touche;
exit(1);
}
p10 =0xFD;
t=p10;
if(t==0xDD){
touche ='5';
return touche;
exit(1);
}
if(t==0x7D){
touche ='6';
return touche;
exit(1);
}
if(t==0xBD){
touche ='4';
return touche;
exit(1);
}
p10 =0xFB;
t=p10;
if(t==0xDB){
touche ='8';
return touche;
exit(1);
}
if(t==0x7B){
touche ='9';
return touche;
exit(1);
}
if(t==0xEB){
touche ='7';
return touche;
exit(1);
}
p10 =0xF7;
t=p10;
if(t==0xE7){
touche ='*';
return touche;
exit(1);
}
if(t==0x77){
touche ='#';
return touche;
exit(1);
}
if(t==0xD7){
touche ='0';
return touche;
exit(1);
}

}
}
}



void affiche_touche(void){
char a;
a = touche();
lcd_char(a);
}

int decode_int(char c)
{

int resultat= c-48;
if (resultat>-1 && resultat<10){
return resultat;
}
else return -1;


}

//ne marche pas fonction add
/*
void add(void){
char a,b;
int ia,ib;
char res[2];
int i;
lcd_str("Entree deux chiffre ");
for(i=0;i<60;i++){
tpo_ms(500);
}
lcd_com(0x01);
tpo_ms(500);
lcd_str("A = ");
tpo_ms(500);
a = touche();
lcd_char(a);
for(i=0;i<60;i++){
tpo_ms(500);
}
lcd_com(0x01);

tpo_ms(500);
lcd_str("B = ");
tpo_ms(500);
b = touche();
lcd_char(b);
for(i=0;i<60;i++){
tpo_ms(500);
}
lcd_com(0x01);

tpo_ms(500);
ia= decode_int(a);
ib = decode_int(b);
ia = ia+ib;

ib = ia%10;
res[1] = (char)ib;
ia = ia-ib;
ia = ia/10;
res[0] = (char)ib;

lcd_str("A+B = ");
for(i=0;i<60;i++){
tpo_ms(500);
}
lcd_char(res[0]);
lcd_char(res[1]);

}
*/

478 ahkurklu
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);
479 ahkurklu
lcd_com(0x0F);
478 ahkurklu
lcd_com(0x01);
tpo_ms(5);
}