|
/***********************************************************************/
|
|
/* */
|
|
/* FILE :SP4b2.c */
|
|
/* DATE :Tue, May 25, 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"
|
|
|
|
// declaration fonctions LCD
|
|
|
|
void lcd_4b(unsigned char car) // envoi des 4 bits de poids fort
|
|
{
|
|
//pd3=0xFF; // definir les ports du registres pDi ouvert
|
|
//p1_2=0; // commande signal E
|
|
//p1_4=1;
|
|
//p1_5=1;
|
|
//p1_6=1;
|
|
//p1_7=1;
|
|
|
|
//p1_4=0;
|
|
//p1_5=1;
|
|
//p1_6=0;
|
|
//p1_7=1;
|
|
|
|
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) // envoi des 8 bits de donn?e
|
|
{
|
|
// char a;
|
|
// a=c<<4;
|
|
// Lcd_4b(a)
|
|
|
|
// p1_3=p1_7;
|
|
// p1_2=p1_6;
|
|
// p1_1=p1_5;
|
|
// p1_0=p1_4;
|
|
|
|
lcd_4b(car);
|
|
lcd_4b(car<<4);
|
|
}
|
|
|
|
|
|
void lcd_com(unsigned char car) // envoi d'une commande
|
|
{
|
|
p3_0=0; // autorise l'envoi de commande
|
|
lcd_8b(car);
|
|
}
|
|
|
|
void lcd_car(unsigned char car) // envoi d'une donn?e ? afficher
|
|
{
|
|
p3_0=1; // autorise envoi caracteres
|
|
lcd_8b(car);
|
|
}
|
|
|
|
void tpo_us(unsigned short duree) // temporisation en ?s
|
|
{
|
|
tcspr = 0x8A;
|
|
ta0mr = 0x82;
|
|
ta0 = duree;
|
|
ta0s = 1;
|
|
ta0os = 1;
|
|
ta0ic = 0x00;
|
|
while(ir_ta0ic != 1);
|
|
ta0s = 0;
|
|
}
|
|
|
|
|
|
void tpo_ms(unsigned short duree)// temporisation en ms
|
|
{
|
|
tcspr = 0x8A;
|
|
ta0mr = 0x82;
|
|
ta0 = duree*1000;
|
|
ta0s = 1;
|
|
ta0os = 1;
|
|
ta0ic = 0x00;
|
|
while(ir_ta0ic != 1);
|
|
ta0s = 0;
|
|
}
|
|
|
|
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(0x0E);
|
|
lcd_com(0x01);
|
|
tpo_ms(5);
|
|
|
|
}
|
|
|
|
|
|
void lcd_str(unsigned char *str)
|
|
{
|
|
int i=0;
|
|
while(str[i]!='\0')
|
|
{
|
|
lcd_car(str[i]);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
//void lcd_clear (void)
|
|
//{
|
|
// lcd_com(0x01);
|
|
//}
|
|
|
|
// Declaration Fonctions KeyBoard
|
|
|
|
|
|
void init_keyboard(void){
|
|
pd10 = 0x0F; // mettre broche 0 a 3 = 1 (sorties) et broches 4 a 7 =0 (entr?e)
|
|
p10=0;
|
|
pu31 = 1; // activation resistance pull-up ( broches 4 a 7 au VDD)
|
|
|
|
}
|
|
|
|
/*void keyboard (void)
|
|
{
|
|
|
|
|
|
|
|
init_keyboard();
|
|
lcd_init();
|
|
while(1)
|
|
{
|
|
if ( (p10 & 0xf0)!= 0xf0 )//les colonnes sont en entrees
|
|
{
|
|
touche= p10 ; // on enleve le phenomene de rebon en ajoutant la tempo
|
|
// tempo car quand j'appuis sur le boutton il affiche rien
|
|
// et quand je lache il affiche
|
|
tpo_ms() ;
|
|
|
|
|
|
|
|
//test ligne 4
|
|
p10=0x07;
|
|
t=p10;
|
|
if (t==0x77)
|
|
{
|
|
//lcd_com(0x01); // clear
|
|
//tpo_ms(15); // tempo car quand j'appuis sur le boutton il affiche rien
|
|
// et quand je lache il affiche
|
|
touche_ap='#';
|
|
lcd_str("#");
|
|
}
|
|
if(t==0xD7)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='0';
|
|
lcd_str("Arret Alarme");
|
|
}
|
|
if (t==0xE7)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='*';
|
|
lcd_str("*");
|
|
}
|
|
|
|
// test ligne 3
|
|
p10=0x0B;
|
|
t=p10;
|
|
if (t==0x7B)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='9';
|
|
lcd_str("...");
|
|
}
|
|
if(t==0xDB)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='8';
|
|
lcd_str("...");
|
|
}
|
|
if (t==0xEB)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='7';
|
|
lcd_str("Ajout Zone");
|
|
}
|
|
|
|
// test ligne 2
|
|
|
|
p10=0x0D;
|
|
t=p10;
|
|
if (t==0x7D)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='6';
|
|
lcd_str("...");
|
|
}
|
|
if(t==0xDD)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='5';
|
|
lcd_str("130 km/h");
|
|
}
|
|
if (t==0xBD)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='4';
|
|
lcd_str("110 km/h");
|
|
}
|
|
|
|
// test ligne 1
|
|
|
|
p10=0x0E;
|
|
t=p10;
|
|
if (t==0x7E)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='3';
|
|
lcd_str("90 km/h");
|
|
}
|
|
if(t==0xDE)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='2';
|
|
lcd_str("70 km/h");
|
|
}
|
|
if (t==0xBE)
|
|
{
|
|
//lcd_com(0x01); // clear
|
|
//tpo_ms(15);
|
|
touche_ap='1';
|
|
lcd_str("50 km/h");
|
|
}
|
|
|
|
|
|
pu31=1;
|
|
}
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
void main(void)
|
|
{
|
|
// declaration variables
|
|
char t;
|
|
unsigned char touche = 0;
|
|
unsigned char touche_ap;
|
|
touche=p10;
|
|
//unsigned char c[]="j'ai reussi";
|
|
//pd3=0xFF;
|
|
//lcd_init(); //initialiser avant d'envoyer !!
|
|
//lcd_car(c);
|
|
//lcd_str(c);
|
|
//keyboard();
|
|
init_keyboard();
|
|
lcd_init();
|
|
while(1)
|
|
{
|
|
//test ligne 4
|
|
p10=0x07;
|
|
t=p10;
|
|
if (t==0x77)
|
|
{
|
|
lcd_com(0x01); // clear
|
|
//tpo_ms(15); // tempo car quand j'appuis sur le boutton il affiche rien
|
|
// et quand je lache il affiche
|
|
touche_ap='#';
|
|
lcd_str("#");
|
|
}
|
|
if(t==0xD7)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='0';
|
|
lcd_str("Arret Alarme");
|
|
}
|
|
if (t==0xE7)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='*';
|
|
lcd_str("*");
|
|
}
|
|
|
|
// test ligne 3
|
|
p10=0x0B;
|
|
t=p10;
|
|
if (t==0x7B)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='9';
|
|
lcd_str("...");
|
|
}
|
|
if(t==0xDB)
|
|
{
|
|
//lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='8';
|
|
lcd_str("...");
|
|
}
|
|
if (t==0xEB)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='7';
|
|
lcd_str("Ajout Zone");
|
|
}
|
|
|
|
// test ligne 2
|
|
|
|
p10=0x0D;
|
|
t=p10;
|
|
if (t==0x7D)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='6';
|
|
lcd_str("...");
|
|
}
|
|
if(t==0xDD)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='5';
|
|
lcd_str("130 km/h");
|
|
}
|
|
if (t==0xBD)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='4';
|
|
lcd_str("110 km/h");
|
|
}
|
|
|
|
// test ligne 1
|
|
|
|
p10=0x0E;
|
|
t=p10;
|
|
if (t==0x7E)
|
|
{
|
|
touche=t;
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='3';
|
|
lcd_str("90 km/h");
|
|
}
|
|
if(t==0xDE)
|
|
{
|
|
lcd_com(0x01);
|
|
//tpo_ms(15);
|
|
touche_ap='2';
|
|
lcd_str("70 km/h");
|
|
}
|
|
if (t==0xBE)
|
|
{
|
|
lcd_com(0x01); // clear
|
|
//tpo_ms(15);
|
|
touche_ap='1';
|
|
lcd_str("50 km/h");
|
|
}
|
|
|
|
pu31=1;
|
|
}
|
|
|
|
|
|
while(t==touche_ap)
|
|
{
|
|
//touche= p10; // on enleve le phenomene de rebon en ajoutant la tempo
|
|
// tempo car quand j'appuis sur le boutton il affiche rien
|
|
// et quand je lache il affiche
|
|
tpo_ms(15) ;
|
|
|
|
}
|
|
lcd_car(touche_ap);
|
|
lcd_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//void lcd_4b(unsigned char car);
|
|
//void lcd_8b(unsigned char car);
|
|
//void lcd_com(unsigned char com);
|
|
//void lcd_init(void);
|
|
//void lcd_car(unsigned char car);
|
|
//void tpo_us(unsigned short duree); // temporisation en ?s
|
|
//void tpo_ms(unsigned short duree); // temporisation en ms
|
|
//void lcd_str(unsigned char *str); // envoi d'une cha?ne de caract?re/*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|