Code: Select all
#define adr_panneau 0
//Déclarations des messages de l'afficheur LCD----------------------------------
const char string_menu1[]="1: Reinit.";
const char string_menu2[]="2: Capture";
const char string_menu3[]="3: Envoi PC";
const char string_menu4[]="4: Cloture";
const char string_choix_calibre1[]="Choix calibre :";
const char string_choix_calibre2[]="1: 24V - 5A";
const char string_choix_calibre3[]="2: 24V - 2,5A";
const char string_choix_calibre4[]="Votre choix ?";
const char string_cloture1[]="Debranchez la";
const char string_cloture2[]="Puissance";
const char string_cloture3[]="Puis eteignez le";
const char string_cloture4[]="Caracteriseur";
const char string_init1[]="CARACTERISEUR";
const char string_init2[]="Version 1.0.0.1";
const char string_init3[]="IUT TARBES";
const char string_init4[]="Mr Demarcq";
const char string_branche1[]= "Branchez la";
const char string_branche2[]="Puissance";
const char string_branche3[]="Puis appuyez";
const char string_branche4[]="sur 1 bouton";
const char string_operation1[]="1: Lancer";
const char string_operation2[]="2: Annuler";
const char string_operation3[]="Votre choix ?";
//Déclarations de variables-----------------------------------------------------
char text[3];
char conductance;
char message_lcd[15];
//Sous-programmes et main-------------------------------------------------------
//Sous programme permettant d'envoyer un message sur le port série
void ecrire_msg_uart(char *message)
{
while(*message != 0)
USART_write(*(message++));
}
//Sous programme permettant l'envoi d'un nombre sur le port série
void envoi_nombre_uart(int nbconv)
{
unsigned short cent,diz,unit;
cent = nbconv /100;
diz = (nbconv - ((cent)*100))/10;
unit = (nbconv - (diz*10));
cent = cent + 48;
Usart_write(cent);
diz = diz + 48;
Usart_Write(diz);
unit = unit + 48;
Usart_Write(unit);
}
//Sous programme de test de la communication par le port série du caractériseur
//avec l'ordinateur
void test_communication_RS232()
{
unsigned short i=0;
do
{
if (USART_Data_Ready())
{
i = USART_Read();
}
}
while(i!='c');
ecrire_msg_uart("Caracteriseur OK\r\n");
}
//Sous programme permettant de copier un 'const char' dans un 'char'
//'const char' est dans la ROM et 'char' est dans la ROM cette fonction est a
//utiliser avec LCD_OUT par exemple pour éviter d'avoir des chaines de coupées.
void text_ROM_to_RAM(char *str1, const char *cstr2)
{
unsigned short i = 0;
do {
str1[i] = cstr2[i];
}
while (str1[i++]);
}
//Sous programme d'affichage de l'opération en cours ainsi que l'avancement
//Ligne 1 : Nom de l'opération
//Ligne 3 : Pourçentage de l'avancement
//Ligne 4 : Barre de progression
void barre_pourcent(char *ligne1,char col, char valeur1)
{
char i;
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
LCD_Out(1,col, ligne1);
LCD_Out(2,1, "");
inttostr(((valeur1*100)/NBRE_CONV), text);
LCD_Out(3,0,text);
LCD_Out(3,7,"%");
for (i=0; i<=((valeur1*16)/NBRE_CONV);i++)
{
LCD_Out(4,-3 + i, CARAC_POURCENT);
}
}
//Programme permettant d'afficher le menu de lancement des opérations et de
//capture. Valeur retournées : 1= Lancement de l'opération
// 0= Annulation de l'opération
char lance_operation(char *operation)
{
char bouton_ok=0, lance;
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
//Affichage "Debranchez la"
text_ROM_to_RAM(message_lcd, operation) ;
LCD_Out(1,1, message_lcd);
//Affichage "Puissance"
text_ROM_to_RAM(message_lcd, string_operation1) ;
LCD_Out(2,1, message_lcd);
//Affichage "Puis eteignez le"
text_ROM_to_RAM(message_lcd, string_operation2) ;
LCD_Out(3,-3,message_lcd);
//Affichage "Caracteriseur"
text_ROM_to_RAM(message_lcd, string_operation3) ;
LCD_Out(4,-3,message_lcd);
do
{
if (PORTB.F5==1)
{
bouton_ok = 1;
lance = 1;
}
else if (PORTB.F4==1)
{
bouton_ok = 1;
lance = 0;
}
else lance = 0;
}
while(bouton_ok!=1);
return(lance);
}
//Sous programme d'affichage du menu
void Affich_Menu()
{
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
//Affiche "1: Reinit"
text_ROM_to_RAM(message_lcd, string_menu1) ;
LCD_Out(1,1, message_lcd);
//Affiche "2: Capture"
text_ROM_to_RAM(message_lcd, string_menu2) ;
LCD_Out(2,1, message_lcd);
//Affiche "3: Envoi PC"
text_ROM_to_RAM(message_lcd, string_menu3) ;
LCD_Out(3,-3,message_lcd);
//Affiche "4: Cloture"
text_ROM_to_RAM(message_lcd, string_menu4) ;
LCD_Out(4,-3,message_lcd);
}
//Sous programme d'initialisation du caractériseur
void Init_Carac()
{
TRISB=0xFF; //Initialisation de l'afficheur sur le port D du PIC
LCD_Init(&PORTD); //Initialisation de l'afficheur LCD sur le portD
//Affichage des informations du caractériseur
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
//Affichage "CARACTERISEUR"
text_ROM_to_RAM(message_lcd, string_init1) ;
LCD_Out(1,2, message_lcd);
//Affichage "Versioon 1.0.0.1"
text_ROM_to_RAM(message_lcd, string_init2) ;
LCD_Out(2,1, message_lcd);
//Affichage "IUT TARBES"
text_ROM_to_RAM(message_lcd, string_init3) ;
LCD_Out(3,0,message_lcd);
//Affichage "Mr Demarcq"
text_ROM_to_RAM(message_lcd, string_init4) ;
LCD_Out(4,0,message_lcd);
delay_ms(5000);
//Affichage du menu
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
do
{
//Affichage "Branchez le"
text_ROM_to_RAM(message_lcd, string_branche1) ;
LCD_Out(1,3,message_lcd);
//Affichage "puissance"
text_ROM_to_RAM(message_lcd, string_branche2) ;
LCD_Out(2,4,message_lcd);
//Affichage "Puis appuyer"
text_ROM_to_RAM(message_lcd, string_branche3) ;
LCD_Out(3,-1,message_lcd);
//Affichage "Sur un bouton"
text_ROM_to_RAM(message_lcd, string_branche4) ;
LCD_Out(4,-1,message_lcd);
}
while((PORTB.F1==0) & (PORTB.F2==0) & (PORTB.F4==0) & (PORTB.F5==0));
delay_ms(100);
Affich_Menu();
}
//Sous programme de cloture. Il permet de débrancher le boitier puissance et de
//bloquer le caractériseur en fin de mesures.
void cloture()
{
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
//Affichage "Debranchez la"
text_ROM_to_RAM(message_lcd, string_cloture1) ;
LCD_Out(1,1, message_lcd);
//Affichage "Puissance"
text_ROM_to_RAM(message_lcd, string_cloture2) ;
LCD_Out(2,1, message_lcd);
//Affichage "Puis eteignez le"
text_ROM_to_RAM(message_lcd, string_cloture3) ;
LCD_Out(3,-3,message_lcd);
//Affichage "Caracteriseur"
text_ROM_to_RAM(message_lcd, string_cloture4) ;
LCD_Out(4,-3,message_lcd);
}
//Sous programme de choix du calibre courant du panneau à controller.
void choix_calibre()
{
char choix_calibre=0;
LCD_Cmd(LCD_CLEAR);
LCD_Cmd(LCD_CURSOR_OFF);
//Afficage de "Choix calibre :"
text_ROM_to_RAM(message_lcd, string_choix_calibre1) ;
LCD_Out(1,1, message_lcd);
//Affichage de "1: 24V - 5A"
text_ROM_to_RAM(message_lcd, string_choix_calibre2) ;
LCD_Out(2,1, message_lcd);
//Affichage "2: 24V - 2,5A"
text_ROM_to_RAM(message_lcd, string_choix_calibre3) ;
LCD_Out(3,-3,message_lcd);
//Affichage "Votre choix ?"
text_ROM_to_RAM(message_lcd, string_choix_calibre4) ;
LCD_Out(4,-3,message_lcd);
do
{
if (PORTB.F5==1)
{
conductance = 2;
choix_calibre = 1;
}
else if (PORTB.F4==1)
{
conductance = 1;
choix_calibre = 1;
}
else choix_calibre = 0;
}
while(choix_calibre!=1);
}
//Sous programme de capture. C'est ce programme qui permet de faire les captures
// et de les stocker dans l'eeprom du pic
void capture()
{
char lance_ok=0;
unsigned short i,j = 0, k = 50;
delay_ms(100);
choix_calibre();
lance_ok=lance_operation("Test lancement");
while(lance_ok)
{
for (i=0;i<=NBRE_CONV-1;i++)
{
EEprom_Write(i, j++);
delay_ms(500);
EEprom_Write(i+50, k--);
delay_ms(500);
EEprom_Write(i+100, j++);
delay_ms(500);
EEprom_Write(i+150, k--);
delay_ms(500);
EEprom_Write(i+200, j++);
delay_ms(500);
barre_pourcent("Capture",4,i);
delay_ms(500);
}
}
delay_ms(100);
Affich_Menu();
}
//Sous programme de restitution. Ce programme permet de restituer les mesures
//sauvegardées dans l'eeprom du PIC
void Restitution()
{
unsigned short i,j = 0, k = 50, lecture;
test_communication_RS232();
ecrire_msg_uart("Caractériseur OK\n");
for (i=0;i<=NBRE_CONV-1;i++)
{
envoi_nombre_uart(i+1);
ecrire_msg_uart(":");
lecture = EEprom_Read(i);
envoi_nombre_uart(lecture);
ecrire_msg_uart(":");
lecture = EEprom_Read(i+50);
envoi_nombre_uart(lecture);
ecrire_msg_uart(":");
lecture = EEprom_Read(i+100);
envoi_nombre_uart(lecture);
ecrire_msg_uart(":");
lecture = EEprom_Read(i+150);
envoi_nombre_uart(lecture);
ecrire_msg_uart(":");
lecture = EEprom_Read(i+200);
envoi_nombre_uart(lecture);
ecrire_msg_uart("\r\n");
delay_ms(500);
barre_pourcent("Envoi PC",3,i);
}
delay_ms(100);
Affich_Menu();
}
//Programme MAIN . C'est le programme principal du caractériseur, il gère les
//autres sous programmes.
void main()
{
char menu=1;
init_carac();
USART_Init(9600);
affich_menu();
while(menu)
{
if (PORTB.F5==1) //bouton1 = 1
{
Init_Carac(); //Réinitialisation de l'afficheur
}
else if (PORTB.F4==1) //bouton2 = 1
{
capture(); //Lancement des mesures
}
else if (PORTB.F2==1) //bouton3 = 1
{
restitution();; //Restitution des données sur le PC
}
else if (PORTB.F1==1) //Bouton4 = 1
{
menu=0;
Cloture();
}
}
}