• Welcome to LusoRobótica - Robótica em Português.
 

Problema com Codigo em C

Started by fiasgardone, 05 de April de 2011, 12:15

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fiasgardone

Pessoal tudo bem!

Estor a tentar trabalhar com um GLCD 128X64 pela primeira vez e para primeiro como periféricos tenho um sensor de temperatura Ds1631, um DS1307 para o horario e um teclado 4X4¨!!

O problema è que o é que o ciclo WHILE nõ funciona com os tres parametro do while, ou seja segue em baixo o cilo do qual não funciona
while(true)
{

ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,min,sec);

sprintf(v_hrs,"%02u",hrs);
glcd_text57(5,5,v_hrs,1,on);
sprintf(v_min,"%02u",min);
glcd_text57(25,5,v_min ,1,on);
sprintf(v_sec,"%02u",sec);
glcd_text57(45,5,v_sec ,1,on);


k=kbd_getc();
if(k!=0)
{
k=k-48;
sprintf(kk,"%02u",k);
glcd_text57(10,35,kk ,1,on);
}



delay_ms(750);
adc = read_temp_c();
if (mystring != adc) {
glcd_text57(50, 35, mystring, 1, Off);
sprintf(mystring,"%02.1f",adc);
glcd_text57(50, 35, mystring, 1, ON);
mystring = adc;
}
}
}


Mas se eu retirar aparte do codigo que mostra o teclado funciona bem o relogio e o sensor de temperatura ,como em baixo
while(true)
{

ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,min,sec);

sprintf(v_hrs,"%02u",hrs);
glcd_text57(5,5,v_hrs,1,on);
sprintf(v_min,"%02u",min);
glcd_text57(25,5,v_min ,1,on);
sprintf(v_sec,"%02u",sec);
glcd_text57(45,5,v_sec ,1,on);



delay_ms(750);
adc = read_temp_c();
if (mystring != adc) {
glcd_text57(50, 35, mystring, 1, Off);
sprintf(mystring,"%02.1f",adc);
glcd_text57(50, 35, mystring, 1, ON);
mystring = adc;
}
}
}


Se ponho o codigo do teclado no WHILE só funciona dentro dum for()

For(;;){
k=kbd_getc();
if(k!=0)
{
k=k-48;
sprintf(kk,"%02u",k);
glcd_text57(10,35,kk ,1,on);
}
}

SE ponho a parte do codio do teclado com o for () juntamente com os outro paramentros no mesmo ciclo WHILE só funciona a parte do teclado o resto fica bloqueado!!
Algem me pode ajudar a resolver isto ,eu jà não tenho conhecimento para mais !!

O Codigo completo è este!!
#include <18f452.h>                    //PIC A UTILIZAR
#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //Reset when brownout detected
#FUSES NOPUT                    //No Power Up Timer
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
                              //CRISTAL
#use delay(clock=8000000)               //A 8MHZ

#include <HDM64GS12.c>
#include <graphics.c>
#include <math.h>

#include <JJJDS1631.c>
#include <RTCC_DS1307.c>
#include <FLEX_KBD4X4.c>

#use standard_io(a)
#use standard_io(e)
#use standard_io(c)


#define DAL_SCL PIN_C2
#define DAL_SDA PIN_C3

BYTE sec,min,hrs,day,month,yr,dow;

char  v_sec[2]; //
char  v_min[2];  //
char  v_hrs[2];
char  v_day[2];
char  v_month[2];
char  v_yr[2];
char  v_dow[2];
char  kk[2];
char  ponto[2]=":";
char mystring[20];
float adc;
int i,k=0;

main()
{
byte old_sec = 0xFF;
//BYTE sec,min,hrs,day,month,yr,dow;
setup_ccp1(ccp_off);
setup_ccp2(ccp_off);

kbd_init();//inicilaliza o teclado
delay_ms(100);
init_temp();//inicializa a temperatura
ds1307_init();//inicializa calendario

glcd_init(ON); // iniciamos o lcd
glcd_fillScreen(OFF); //LIMPAMOS

ds1307_set_date_time(15,6,5,2,22,35,00);

glcd_rect(0,0,127,15,0,1);
glcd_text57(18,5,ponto,1,on);
glcd_text57(38,5,ponto,1,on);

while(true)
{

ds1307_get_date(day,month,yr,dow);
ds1307_get_time(hrs,min,sec);

sprintf(v_hrs,"%02u",hrs);
glcd_text57(5,5,v_hrs,1,on);
sprintf(v_min,"%02u",min);
glcd_text57(25,5,v_min ,1,on);
sprintf(v_sec,"%02u",sec);
glcd_text57(45,5,v_sec ,1,on);

For(;;){ /// com o for só funciona o teclado
k=kbd_getc();
if(k!=0)
{
k=k-48;
sprintf(kk,"%02u",k);
glcd_text57(10,35,kk ,1,on);
}
}


delay_ms(750);
adc = read_temp_c();
if (mystring != adc) {
glcd_text57(50, 35, mystring, 1, Off);
sprintf(mystring,"%02.1f",adc);
glcd_text57(50, 35, mystring, 1, ON);
mystring = adc;
}
}
}


Se não foi claro em algum ponto estejam a vontade em perguntar !!
desde jà agradeço