|
/***********************************************************************/
|
|
/* */
|
|
/* 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. */
|
|
/***********************************************************************/
|
|
|
|
#include "sfr32c87.h"
|
|
|
|
#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
|
|
|
|
|
|
//temporisation en us
|
|
void tpo_us(unsigned short duree){
|
|
tcspr = 0x8A;
|
|
ta0mr = 0x82;
|
|
ta0 = duree;
|
|
ta0s = 1;ta0os = 1;
|
|
ta0ic = 0x00;
|
|
while(ir_ta0ic != 1);
|
|
ta0s = 0;
|
|
}
|
|
|
|
// temporisation en ms
|
|
void tpo_ms(unsigned short duree){
|
|
tpo_us(duree*1000);
|
|
}
|
|
|
|
//envoie des 4 bits de poids fort
|
|
void lcd_4b(unsigned char car){
|
|
LCD_E=1;
|
|
pd3=0xff;
|
|
if (car & 16){
|
|
LCD_PORT4=1;
|
|
}
|
|
else{
|
|
LCD_PORT4=0;
|
|
}
|
|
if (car & 32){
|
|
LCD_PORT5=1;
|
|
}
|
|
else{
|
|
LCD_PORT5=0;
|
|
}
|
|
if (car & 64){
|
|
LCD_PORT6=1;
|
|
}
|
|
else{
|
|
LCD_PORT6=0;
|
|
}
|
|
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);
|
|
|
|
}
|
|
//envoi d'une commande
|
|
void lcd_com(unsigned char com){
|
|
LCD_DC=0;
|
|
lcd_8b(com);
|
|
|
|
}
|
|
|
|
//envoie d'une donn?e ? l'afficheur
|
|
void lcd_car(unsigned char car){
|
|
LCD_DC=1;
|
|
lcd_8b(car);
|
|
}
|
|
|
|
//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;
|
|
}
|
|
}
|
|
|
|
|
|
//void main(void){
|
|
// pd3=0xff;
|
|
// lcd_init();
|
|
// lcd_4b(0xf0);
|
|
// lcd_8b(0x28);
|
|
// lcd_car('a');
|
|
// lcd_car('b');
|
|
// lcd_str("salut");
|
|
//}
|
|
|
|
|
|
//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';
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|