Projet

Général

Profil

/***********************************************************************/
/* */
/* FILE :SP4b2.c */
/* DATE :Fri, May 21, 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 PLCD p3;
#define LCD_DC p3_0;
#define LCD_RW P3_1;
#define LCD_E p3_2;
#define data4 p3_4;
#define data5 p3_5;
#define data6 p3_6;
#define data7 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 de poids fort
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

//LCD//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void init_keyboard(void);
void tpo_50ms(void) ;


void init_keyboard(void)
{
pd10 = 0x0F;
p10=0 ;
pu31 = 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void lcd_4b(unsigned char c)
{

p3_2 = 1;
p3_7 = ( c & 0b10000000)>>7;
p3_6 = ( c & 0b01000000)>>6;
p3_5 = ( c & 0b00100000)>>5;
p3_4 = ( c & 0b00010000)>>4;
p3_2 = 0;
}


void lcd_8b(unsigned char c)
{
lcd_4b(c);
lcd_4b(c<<4);
}

void lcd_com (unsigned char c)
{
p3_0 = 0;
lcd_8b (c);
}

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;
}


// 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 lcd_car(unsigned char car)
{
p3_0 = 1;
lcd_8b(car);
}

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);
}

void main(void)
{
char tab[4][3]={{'1','2','3'}, // L C D ////////////////////////
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}};
char resultat; // L C D ////////////////////////
init_keyboard(); // L C D ////////////////////////
int i;
lcd_init();
while(1) //*** fonction
{
short int colone, ligne;
if ( (p10 & 0xf0)!= 0xf0 ) //le programme attend qu'une touche soit press? //**** bit fort != 1 -> touche press?e
{
if (p10 == 0xB0) //Je test les diff?rentes colone pour identifi? dans laquel on ce situe
{colone=0;}
if (p10 == 0xE0) //Je test les diff?rentes colone pour identifi? dans laquel on ce situe
{colone=0;}
if (p10 == 0xD0) //((p10 & 0xf0) == 0xD0)
{colone=1;}
if (p10 == 0x70)
{colone=2;}
p10 = 0x0E; //Je test les diff?rentes ligne pour identifi? dans laquel on ce situe
if ((p10 & 0xF0)!= 0xF0)
{ligne = 0;}
p10 = 0x0D;
if ((p10 & 0xF0)!= 0xF0)
{ligne = 1;}
p10 = 0x0B;
if ((p10 & 0xF0)!= 0xF0)
{ligne = 2;}
p10 = 0x07;
if ((p10 & 0xF0)!= 0xF0)
{ligne = 3;}
resultat = tab[ligne][colone];
lcd_clear ();
for (i=0;i<=20;i++)
{
tpo_ms(50);
}
lcd_car(resultat);

}
p10 = 0;
}
}
(2-2/9)