root/branch/soleillant/sp4b2/SP4b2/SP4b2.c @ 504
501 | jgsoleilla | /***********************************************************************/
|
|
/* */
|
|||
/* 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"
|
|||
#define LCD_RS p3_0
|
|||
#define LCD_RW p3_1
|
|||
#define LCD_E p3_2
|
|||
#define LCD_DB4 p3_4
|
|||
#define LCD_DB5 p3_5
|
|||
#define LCD_DB6 p3_6
|
|||
#define LCD_DB7 p3_7
|
|||
void tpo_us(unsigned short duree);// temporisation en ?s
|
|||
void tpo_ms(unsigned short duree);// temporisation en ms
|
|||
void lcd_init_port(void); // initialisation des broches du ?C
|
|||
void lcd_4b(unsigned char car); // envoi des 4 bits
|
|||
void lcd_8b(unsigned char car); // envoi des 8 bits de donn?e
|
|||
void lcd_car(unsigned char car);// envoi d'une donn?e ? afficher
|
|||
void lcd_com(unsigned char com);// envoi d'une commande
|
|||
void lcd_init(void); // initialisation de l'afficheur
|
|||
void lcd_str(unsigned char *str); // envoi d'une cha?ne de caract?re
|
|||
void main(void)
|
|||
{
|
|||
504 | jgsoleilla | ||
char t;
|
|||
unsigned char touche;
|
|||
pu31 =1;
|
|||
pd10 = 0x0F;
|
|||
501 | jgsoleilla | lcd_init_port();
|
|
lcd_init();
|
|||
504 | jgsoleilla | //lcd_str("Bonjour");
|
|
501 | jgsoleilla | ||
504 | jgsoleilla | // while(1){
|
|
// touche = clavier();
|
|||
// }
|
|||
501 | jgsoleilla | }
|
|
void lcd_init_port(void){
|
|||
pd3 = 0xFF;
|
|||
}
|
|||
void lcd_init(void){
|
|||
tpo_ms(15);
|
|||
lcd_4b(0x30);
|
|||
tpo_ms(5);
|
|||
lcd_4b(0x30);
|
|||
tpo_us(100);
|
|||
lcd_4b(0x30);
|
|||
tpo_us(100);
|
|||
lcd_4b(0x20); //mode 4 bits activ?
|
|||
lcd_com(0x28); //mode 4bits - 2 lignes
|
|||
lcd_com(0x06); //Incremente vers la gauche
|
|||
lcd_com(0x0E); //LCD ? on, curseur ? on
|
|||
lcd_com(0x01); //Clear LCD
|
|||
tpo_ms(5);
|
|||
}
|
|||
void lcd_4b(unsigned char car){
|
|||
LCD_E = 1;
|
|||
if (car & 16){ //16 bit poids fort
|
|||
LCD_DB4 = 1;
|
|||
}
|
|||
else{
|
|||
LCD_DB4 = 0;
|
|||
}
|
|||
if (car & 32){ //32
|
|||
LCD_DB5 = 1;
|
|||
}
|
|||
else{
|
|||
LCD_DB5 = 0;
|
|||
}
|
|||
if (car & 64){ //64
|
|||
LCD_DB6 = 1;
|
|||
}
|
|||
else{
|
|||
LCD_DB6 = 0;
|
|||
}
|
|||
if (car & 128){ //128
|
|||
LCD_DB7 = 1;
|
|||
}
|
|||
else{
|
|||
LCD_DB7 = 0;
|
|||
}
|
|||
tpo_us(5);
|
|||
LCD_E = 0;
|
|||
tpo_us(5);
|
|||
}
|
|||
void lcd_8b(unsigned char car){
|
|||
lcd_4b(car);
|
|||
lcd_4b(car<<4);
|
|||
}
|
|||
void lcd_com(unsigned char com){
|
|||
LCD_RS = 0;
|
|||
lcd_8b(com);
|
|||
}
|
|||
void lcd_car(unsigned char car){
|
|||
LCD_RS = 1;
|
|||
lcd_8b(car);
|
|||
}
|
|||
void lcd_str(unsigned char *str){
|
|||
int i = 0;
|
|||
while (str[i] != '\0'){
|
|||
lcd_car(str[i]);
|
|||
i++;
|
|||
}
|
|||
}
|
|||
504 | jgsoleilla | /*
|
|
unsigned char clavier(void){
|
|||
p10 = 0x0E;
|
|||
t = p10;
|
|||
unsigned char touche;
|
|||
if (t == 0xBE){
|
|||
touche = '1';
|
|||
}
|
|||
if (t == 0xDE){
|
|||
touche = '2';
|
|||
}
|
|||
if (t == 0x7E){
|
|||
touche = '3';
|
|||
}
|
|||
p10 = 0x0D;
|
|||
t = p10;
|
|||
if (t == 0xBD){
|
|||
touche = '4';
|
|||
}
|
|||
if (t == 0xDD){
|
|||
touche = '5';
|
|||
}
|
|||
if (t == 0x7D){
|
|||
touche = '6';
|
|||
}
|
|||
p10 = 0x0B;
|
|||
t = p10;
|
|||
if (t == 0xEB){
|
|||
touche = '7';
|
|||
}
|
|||
if (t == 0xDB){
|
|||
touche = '8';
|
|||
}
|
|||
if (t == 0x7B){
|
|||
touche = '9';
|
|||
}
|
|||
p10 = 0x07;
|
|||
t = p10;
|
|||
if (t == 0xE7){
|
|||
touche = '*';
|
|||
}
|
|||
if (t == 0xD7){
|
|||
touche = '0';
|
|||
}
|
|||
if (t == 0x77){
|
|||
touche = '#';
|
|||
}
|
|||
return touche;
|
|||
}
|
|||
*/
|
|||
501 | jgsoleilla | void tpo_ms(unsigned short duree){
|
|
tcspr = 0x8A;
|
|||
ta0mr = 0x82;
|
|||
ta0 = duree * 1000;
|
|||
ta0s = 1;
|
|||
ta0os = 1;
|
|||
ta0ic = 0x00;
|
|||
while(ir_ta0ic != 1);
|
|||
ta0s = 0;
|
|||
}
|
|||
void tpo_us(unsigned short duree){
|
|||
tcspr = 0x8A;
|
|||
ta0mr = 0x82;
|
|||
ta0 = duree;
|
|||
ta0ic = 0x00;
|
|||
ta0s = 1;
|
|||
ta0os = 1;
|
|||
while(ir_ta0ic != 1);
|
|||
ta0s = 0;
|
|||
}
|
|||