|
/***********************************************************************/
|
|
/* */
|
|
/* FILE :SP4b2.c */
|
|
/* DATE :Fri, May 21, 2021 */
|
|
/* DESCRIPTION :main program file. */
|
|
/* CPU GROUP :87B */
|
|
/* */
|
|
/* This file is generated by Renesas Project Generator (Ver.4.18). */
|
|
/* NOTE:THIS IS A TYPICAL EXAMPLE. */
|
|
/***********************************************************************/
|
|
|
|
#include "sfr32c87.h"
|
|
|
|
#define PLCD p1
|
|
#define LCD_DC p3_0;
|
|
#define LCD_RW p3_1;
|
|
#define LCD_E p1_2;
|
|
#define data4 p3_4;
|
|
#define data5 p3_5;
|
|
#define data6 p3_6;
|
|
#define data7 p3_7;
|
|
|
|
void lcd_4b (char c) {
|
|
char valeur4b;
|
|
p3_2=1; //fonction permettant la r?ception des donn?es par l'afficheur
|
|
|
|
p3_7=(c & 0b10000000)>>7;
|
|
p3_6=(c & 0b01000000)>>6;
|
|
p3_5=(c & 0b00100000)>>5;
|
|
p3_4=(c & 0b00010000)>>4;
|
|
|
|
p3_2=0;
|
|
}
|
|
|
|
void tpo_ms (unsigned short duree){
|
|
|
|
duree = duree*1000;
|
|
tcspr = 0x8A;
|
|
ta0mr = 0x82;
|
|
ta0 = duree;
|
|
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_8b (char c) {
|
|
lcd_4b(c);
|
|
lcd_4b(c<<4);
|
|
}
|
|
|
|
// fonction de commande
|
|
void lcd_com (char c) {
|
|
p3_0=0;
|
|
lcd_8b(c);
|
|
|
|
}
|
|
|
|
void lcd_car (char c) {
|
|
p3_0=1;
|
|
lcd_8b(c);
|
|
|
|
}
|
|
|
|
void lcd_str (char *str){
|
|
int i = 0;
|
|
|
|
while (str[i]!='\0')
|
|
{
|
|
lcd_car(str[i]);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
// initialize the LCD display
|
|
void lcd_init(void)
|
|
{
|
|
pd3=0xFF;
|
|
p3=0x00;
|
|
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 init_keyboard(void){
|
|
pd10 = 0x0f;
|
|
p10=0 ;
|
|
pu31 = 1;
|
|
}
|
|
|
|
|
|
void tpo_50ms(void){
|
|
tcspr = 0x8A;
|
|
ta0mr = 0x82;
|
|
ta0 = 50000;
|
|
ta0s = 1;ta0os = 1;
|
|
ta0ic = 0x00;
|
|
while(ir_ta0ic != 1);
|
|
ta0s = 0;
|
|
}
|
|
|
|
|
|
unsigned char touche_c = 0;
|
|
unsigned char touche_appuyee;
|
|
|
|
void main(void){
|
|
init_keyboard();
|
|
lcd_init();
|
|
while(1){
|
|
|
|
init_keyboard();
|
|
|
|
if ( (p10 & 0xf0)!= 0xf0 ){ //les colonnes sont en entr?es
|
|
touche_c = p10 ;
|
|
tpo_50ms() ; // une temporisation entre en oeuvre pour ?viter les ph?nom?nes de rebond
|
|
|
|
p10 = 0x0e;
|
|
if ( (p10 & 0xff)== 0xbe ){ //diff?rents tests
|
|
touche_appuyee = '1';
|
|
}
|
|
if ( (p10 & 0xff)== 0xde ){
|
|
touche_appuyee = '2';
|
|
}
|
|
if ( (p10 & 0xff)== 0x7e ){
|
|
touche_appuyee = '3';
|
|
}
|
|
|
|
p10 = 0x0d;
|
|
if ( (p10 & 0xff)== 0xbd ){
|
|
touche_appuyee = '4';
|
|
}
|
|
if ( (p10 & 0xff)== 0xdd ){
|
|
touche_appuyee = '5';
|
|
}
|
|
if ( (p10 & 0xff)== 0x7d ){
|
|
touche_appuyee = '6';
|
|
}
|
|
|
|
p10 = 0x0b;
|
|
if ( (p10 & 0xff)== 0xeb ){
|
|
touche_appuyee = '7';
|
|
}
|
|
if ( (p10 & 0xff)== 0xdb ){
|
|
touche_appuyee = '8';
|
|
}
|
|
if ( (p10 & 0xff)== 0x7b ){
|
|
touche_appuyee = '9';
|
|
}
|
|
|
|
p10 = 0x07;
|
|
if ( (p10 & 0xff)== 0xe7 ){
|
|
touche_appuyee = '*';
|
|
}
|
|
if ( (p10 & 0xff)== 0xd7 ){
|
|
touche_appuyee = '0';
|
|
}
|
|
if ( (p10 & 0xff)== 0x77 ){
|
|
touche_appuyee = '#';
|
|
}
|
|
lcd_car(touche_appuyee);
|
|
lcd_init();
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|