killerbee
Newbie level 1
hello,
I'm a beginner in programmation, I'm using PIC C as a compiler for my program which is by the way, reads a code composed by 4 numbers and compares it to a postdefined code ( in my case 1234 is the reference), but still won't do the loop to test it please help!!!
I'm a beginner in programmation, I'm using PIC C as a compiler for my program which is by the way, reads a code composed by 4 numbers and compares it to a postdefined code ( in my case 1234 is the reference), but still won't do the loop to test it please help!!!
Code:
#include "16F877A.h"
#include "string.h"
#use delay(clock=10M)
#byte PORTB= 0x06
#byte PORTC= 0x07
#byte TRISB= 0x86
#byte TRISC= 0x87
#byte PORTD= 0x08
#byte TRISD= 0x88
#bit E =PORTC.0
#bit RS=PORTC.1
#bit C1=PORTD.0
#bit C2=PORTD.1
#bit C3=PORTD.2
#define string_size 4
char texte[28]="veuillez saisir le code ";
char Tvrep[13]="code correct";
char Tfrep[15]="code incorrect";
int i;
char touche=' ';
void envoie_commande(char commande)
{
E=0;
RS=0;//mode commande
PORTB=commande;
E=1;
delay_us(50);
E=0;
}
void envoie_caractere(char caractere)
{
E=0;
RS=1;//mode affichage
PORTB=caractere;
E=1;
delay_us(50);
E=0;
}
#int_timer0
void clavier()
{
touche=' ';
PORTD=0x08;//Selection de la ligne A
if(C1==1){touche='1';while(C1==1);}
if(C2==1){touche='2';while(C2==1);}
if(C3==1){touche='3';while(C3==1);}
PORTD=0x10;//Selection de la ligne B
if(C1==1){touche='4';while(C1==1);}
if(C2==1){touche='5';while(C2==1);}
if(C3==1){touche='6';while(C3==1);}
PORTD=0x20;//Selection de la ligne C
if(C1==1){touche='7';while(C1==1);}
if(C2==1){touche='8';while(C2==1);}
if(C3==1){touche='9';while(C3==1);}
PORTD=0x40;//Selection de la ligne D
if(C1==1){touche='*';while(C1==1);}
if(C2==1){touche='0';while(C2==1);}
if(C3==1){touche='#';while(C3==1);}
}
void init_LCD()
{
delay_ms(15);//attendre le démarrage du LCD
envoie_commande(0x3C);//Mode 8bits, 2ligne, 5*10 font
delay_ms(5);
envoie_commande(0x3C);//Mode 8bits, 2ligne, 5*10 font
delay_ms(100);
envoie_commande(0x0E);//display on, Corseur on, blink off
delay_ms(5);
envoie_commande(0x01);// clear dispaly
delay_ms(5);
}
void rotation(int texte[26])
{
int A;
A=Texte[0];
for(i=0;i<25;i++) texte[i]=texte[i+1];
texte[24]=A;
}
void main()
{
char T[4]={1,2,3,4};
char Ts[4];
int cmp;
TRISB=0x00;
TRISC=0xFC;
TRISD=0x87;
setup_timer_0 (RTCC_DIV_128|RTCC_INTERNAL);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
init_LCD();
func1:
while(touche==' ')
{
disable_interrupts(INT_TIMER0);
envoie_commande(0x80);
for(i=0;i<24;i++) envoie_caractere(texte[i]);
{
delay_ms(200);
rotation(texte);
}
enable_interrupts(INT_TIMER0);
}
envoie_commande(0x01);// clear dispaly
delay_ms(5);
for(cmp=0;cmp<5;cmp++)
{
//envoie_commande(0x80);
func2: if (touche!=' ')
{
envoie_caractere('*');
Ts[cmp]=touche;
touche=' ';
}
else {goto func2;}
}
while(true)
{
if(Ts[cmp]!=T[4])
{
//! else{break;}
disable_interrupts(INT_TIMER0);
envoie_commande(0x80);
for(i=0;i<24;i++) envoie_caractere(Tfrep[i]);
{
delay_ms(1000);
rotation(texte);
}
enable_interrupts(INT_TIMER0);
goto func1;
}
else
{
disable_interrupts(INT_TIMER0);
envoie_commande(0x80);
for(i=0;i<24;i++) envoie_caractere(Tvrep[i]);
{
delay_ms(1000);
rotation(texte);
}
enable_interrupts(INT_TIMER0);
}
}
}