hola amigos, espero que me puedan ayudar como siempre lo ha sido este foro, es la primera vez que escribo pero me he guiado muchas veces para mis tareas aqui
Me gustaria saber porque no me da el conteo hacia abajo
me imagino que tiene que ver con la variable Counter en la funcion minus, pues conteo hacia arriba da bien, pero no doy con la respuesta
ademas me gustaria saber si alguien sabe con borrar una sola linea no borrar toda la pantalla pues eso crea un retardo demasiado largo en el LCD
agradezco de ante mano su tiempo y sus respuestas
aqui pongo el video por si no me explique bien el problema
//***************************************************
//COUNTER IN LCD DISPLAY
//F14997024
//***************************************************
#include <p18f4520.h> //PIC18F4520
#include "p18F_LCD.h" //lIBRARY OF LCD
void InitializeTMR0(void); //TIMER0
void InitializeIO(void); //I/O Function
void plus (void);
void minus (void);
#define SW2 PORTBbits.RB0
#define SW3 PORTAbits.RA4
char LCD_MSG1[]="MyTIMER T=0.5s"; //first line
char LCD_MSG2[]="COUNT: "; //counter line
char LCD_MSG3[]="Press SW2 START"; //message line
char LCD_MSG4[]="Counting up..."; //message line
char LCD_MSG5[]="Counting down..."; //message line
unsigned char ASCII_Buf[6] ; //BUFFER
unsigned int Counter; //TIMER 0 counter
unsigned int Polling; //TMR0 polling
int a=0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void)
{
InitializeTMR0(); //TIMER 0
InitializeIO(); //I/O FUNCTION
OpenLCD( );
LCD_Set_Cursor(0,0);
putsLCD(LCD_MSG1);
LCD_Set_Cursor(1,0);
putsLCD(LCD_MSG3);
Polling = 0; //INITIAL Polling
Counter = 0; //INITIAL Counter
T0CONbits.TMR0ON =1; //enable timer2
TRISBbits.TRISB0=1;
TRISAbits.TRISA4=1;
while(1)
{
if(!SW2){
WriteCmdLCD(1);
LCD_Set_Cursor(0,0);
putsLCD(LCD_MSG4);
LCD_Set_Cursor(1,0);
putsLCD(LCD_MSG2);
a=1;
}
else if(!SW3){
WriteCmdLCD(1);
LCD_Set_Cursor(0,0);
putsLCD(LCD_MSG5);
LCD_Set_Cursor(1,0);
putsLCD(LCD_MSG2);
a=2;
}
if(a==2){
minus();
}
if(a==1)
plus();
}// End of while(1)
}//End of main()
void plus (void){
if (TMR0L == 0xfa && TMR0H == 0x00 ){ //1ms
TMR0H = 0x00;
TMR0L = 0x00;
Polling++;
if ( Polling >= 500 ) // T0 period as 0.5s
{ // Y Polling p¼Æ¦Ü250 , «h¬°¸g¹L 1 ¬íªº®É¶¡
Polling = 0 ; // Y Polling >= 250 , «hPolling=0
Counter++; // TMR0p¼ÆÈ
itoa ( Counter , ASCII_Buf ) ; // §Q¥ÎC18 LIBRARY¤¤ªº itoaÂà´« HEX¬°string (ASCII code)
LCD_Set_Cursor(1,7) ; // Set LCD cursor @ (1,7)
putsLCD(ASCII_Buf) ; // ¶Ç°e¸ê®Æ¦ÜLCD¤W
}
}
}//end of function plus
void minus (void){
if (TMR0L == 0xfa && TMR0H == 0x00 ){ //1ms
TMR0H = 0x00;
TMR0L = 0x00;
Polling++;
if ( Polling >= 500 ) // T0 period as 0.5s
{
Polling = 0 ; // Y Polling >= 250 , «hPolling=0
Counter--; //
itoa ( Counter , ASCII_Buf ) ; //
LCD_Set_Cursor(1,7) ; // Set LCD cursor @ (1,7)
putsLCD(ASCII_Buf) ; //
}
}
if (Counter==0){
Counter=0;
LCD_Set_Cursor(1,7) ;
WriteDataLCD(0x30); //zero is smallest number
}
}//end of function minus
void InitializeTMR0(void)
{
T0CON = 0b00000011; //
//bit 7 : STOP THE TIMER
//bit 6 : Run in 16-bit mode
//bit 5 : iNTERNAL CLOCK clk0
//bit 4 : Use system clock to increment timer
//bit 3 : A prescaler is assigned for Timer0
//bit 2-0 : 1:16 prescale
//T=4us
TMR0H = 0x00;
TMR0L = 0x00;
}
void InitializeIO(void)
{
TRISA=0b11111011; // RA2 as LCD-E control and RA4 as input SW3
TRISD=0x00; // Set PORTD as Output port
}