|
|
View previous topic :: View next topic |
Author |
Message |
killerbee
Joined: 12 Dec 2010 Posts: 1 Location: TN
|
program error |
Posted: Sun Dec 12, 2010 10:32 am |
|
|
I'm using 16F877A and I'm blocked in how to copy an entered value from a keyboard to an array already declared empty. But it won't work because in debugging mode the array is always taking the value ' ' (space). I've tried everything but nothing... a little help please!!!
Code: |
#include "16F877A.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
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()
{
int T[4]={1,2,3,4};
int Ts[4];
int cmp,j,code;
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<4;cmp++)
{
//envoie_commande(0x80);
func2: if (touche!=' ')
{
envoie_caractere('*');
touche=' ';
Ts[cmp]=touche;
}
else {goto func2;}
}
for (j=0;j<4;j++)
{
if (Ts[j]==T[j])
{
code=1;
}
else{
code=0;
}
}
while(true)
{
if(code==0)
{
//! 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);
}
}
} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19513
|
|
Posted: Sun Dec 12, 2010 2:02 pm |
|
|
You are not declaring an array.
Single inverted commas, declare a single character.
Declare your array, as:
char touche[5];
Make it large enough to store the charcters you want, _and_ remember the space for the terminating '\0', if you want to use it as a string. Add the characters to this, and remember to add the termination.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|