CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help with creating a menu for a digital clock with ds1302

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
claudia.crespo



Joined: 19 Apr 2013
Posts: 3

View user's profile Send private message

help with creating a menu for a digital clock with ds1302
PostPosted: Fri Apr 19, 2013 1:47 pm     Reply with quote

I'm trying to do a digital clock within a menu of different options
with a pic 18f4550 and a ds1302.
But i get an error at the beginning of all the functions i create Rolling Eyes
"a numeric expression must appear here"
Crying or Very sad
My comments are in spanish but i think is easy to understand.
I'll appreciate the help.
Code:
#include <18f4550.h>  //archivo de cabecera
#fuses hspll,mclr,nowdt,noprotect,nolvp,nodebug,usbdiv,pll5,cpudiv1,novregen,nopbaden
#DEVICE ADC=8                                              // resolucion a 8 bits
#use delay(clock=48000000)                            // clock de trabajo del pic a  48Mhz
#define LCD_DATA_PORT getenv("SFR:PORTB")   // declaro usar el portb para el control del lcd
#include <lcd.c>                            // libreria del lcd
#include <DSS1302.c>                    //Definimos pines DS1307         

///VARIABLES GLOBALES
byte day,mth,year,dow,hour,min,sec;   //variabes para ds1302
byte menu=0,flag=0,var=2;    //variables para menu configurar


 

///DEFINICION DE FUNCIONES   
void configurar(void);
void horas(void);   
void minutos(void);
void dia(void);
void mes(void);
void anio(void);
void beep(void);

///LLAMADA FUNCION INTERRUPCION
#INT_TIMER0
void interrupcion()
{
if(flag>var){    //¿ya es 130ms aprox?
var--;    //SI -> decremento var...
if(var==0)
var=2;    //...ajuste fino de 130ms aprox
flag=0;    //reset flag para contar 130ms aprox


//lcd
}

set_timer0(0);    //reset TMR0
flag++;    //incremento variable flag
}

///PROGRAMA
void main(void){


enable_interrupts(INT_TIMER0);    //interrupcion TIMER0 activada
setup_counters(RTCC_INTERNAL,RTCC_DIV_256);   //configuracion interrupcion TMR0
set_timer0(0);    //carga TMR0

lcd_init(); //inicializa lcd
rtc_init(); //inicializa rtc
rtc_get_date(day,mth,year,dow);    //coge dia,mes,año
rtc_get_time(hour,min,sec );    //coge hora,minuto,segundo

lcd_putc("\f fonzo reloaded\n");
   delay_ms(100);
 
   while (TRUE) {
   
   while (input_state(PIN_D6)==0&& input_state(PIN_D4)==0&& input_state(PIN_D3)==0){
      printf(lcd_putc,"\f seleccione una \n opcion ");
       delay_ms(100);
 
   if (input_state(PIN_D3)==1&&input_state(PIN_D6)==0&& input_state(PIN_D4)==0)
   {printf(lcd_putc,"\f AUDIO  \n");
     delay_ms(500);
     output_high( PIN_D0 );
     Lcd_putc( "\f");   //clear
   }
     
  if (input_state(PIN_D3)==0&&input_state(PIN_D6)==0&& input_state(PIN_D4)==1){
     printf(lcd_putc,"\f recordatorio  \n");
     output_high( PIN_D1 );
     delay_ms(500);
     //grabador de voz
     Lcd_putc( "\f");   //clear
  }
if (input_state(PIN_D3)==0&&input_state(PIN_D6)==1&& input_state(PIN_D4)==0){
printf(lcd_putc,"\fFecha: %2X/%2X/%2X\nHora: %2X:%2X:%2X",day,mth,year,hour,min,sec); 
configurar();    //ve a menu configurar
enable_interrupts(GLOBAL);    //activadas interrupciones

for( ; ; ){    //bucle...
if(input(PIN_C5)==0){    //Si se pulsa Conf....
while(!input(PIN_C5)){}    //elimina rebotes
beep();
configurar();
}    //ve a menu configurar
} //...infinito   
 

///FUNCION CONFIGURAR
 void configurar(void){
disable_interrupts(GLOBAL);    //desactivadas interrupciones

do{
switch(menu){
case 0:   lcd_putc("\fConfigurar\nhoras?" );    //horas
if(!input(PIN_D4)){
while(!input(PIN_D4)){}
beep();
horas();
menu=1;   

//apunta siguiente opcion
}
break;
case 1: lcd_putc("\fConfigurar\nminutos?" );    //minutos
if(!input(PIN_C5)){
while(!input(PIN_C5)){}
beep();
minutos();
menu=2;   

//apunta siguiente opcion
}
break;
case 2: lcd_putc("\fConfigurar\ndia?" );    //dias
if(!input(PIN_C5)){
while(!input(PIN_C5)){}
beep();
dia();
menu=3;   

//apunta siguiente opcion
}
break;
case 3: lcd_putc("\fConfigurar\nmes?" );    //mes
if(!input(PIN_C5)){
while(!input(PIN_C5)){}
beep();
mes();
menu=4;   

//apunta siguiente opcion
}
break;
case 4: lcd_putc("\fConfigurar\nanio?" );    //años
if(!input(PIN_C5)){
while(!input(PIN_C5)){}
beep();
anio();
menu=5;   

//apunta siguiente opcion
}
break;
case 5: lcd_putc("\fSalir\nconfigurar?" );    //salir configuracion
if(!input(PIN_C5)){
menu=6;
beep();
}   
}

if(!input(PIN_C4)){    //controla el boton up...
while(!input(PIN_C4)){}
menu++;
if(menu>5)
menu=0;
}    //...para mostrar menu por lcd

delay_ms(130);    //retardo para ver lcd
}while(menu<6);

menu=0;   

//actualiza indices menu
rtc_set_datetime(day,mth,year,dow,hour,min);   //nueva hora,minuto,...
enable_interrupts(GLOBAL);    //activadas

//interrupciones
set_timer0(0);   

//carga TMR0
}
///FUNCION CONFIGURA HORAS
void horas(void){
printf(lcd_putc,"\fConf.Horas:\nHora: %2X:%2X:%2X",hour,min,sec);   //muestra por lcd
do{
if(!input(PIN_C4)){    //¿se ha pulsado up?
while(!input(PIN_C4)){}    //elimina rebotes
hour++;    //SI ->

//incremento hour
switch(hour){    //limites...
case 0x0A:   hour=0x10;break;   
case 0x1A:   hour=0x20;break;
case 0x24:   hour=0x00;
}   

//...hour
printf(lcd_putc,"\nHora: %2X:%2X:%2X",hour,min,sec);   //muestra por lcd hour
}
}while(input(PIN_C5));
while(!input(PIN_C5)){}    //elimina rebotes
}
///FUNCION CONFIGURA MINUTOS
void minutos(void){
printf(lcd_putc,"\fConf.Minutos:\nHora: %2X:%2X:%2X",hour,min,sec);   //muestra por lcd
do{
if(!input(PIN_C4)){    //¿se ha pulsado up?
while(!input(PIN_C4)){}    //elimina rebotes
min++;    //SI -> incremento min
switch(min){    //limites...
case 0x0A:   min=0x10;break;
case 0x1A:   min=0x20;break;
case 0x2A:   min=0x30;break;
case 0x3A:   min=0x40;break;
case 0x4A:   min=0x50;break;
case 0x5A:   min=0x00;
}    //...min
printf(lcd_putc,"\nHora: %2X:%2X:%2X",hour,min,sec);   //muestra por lcd min
}
}while(input(PIN_C5));
while(!input(PIN_C5)){}    //elimina rebotes
}
///FUNCION CONFIGURA DIAS
void dia(void){
printf(lcd_putc,"\fConf.Dias:\nFecha: %2X/%2X/%2X",day,mth,year);   //muestra por lcd
do{
if(!input(PIN_C4)){    //¿se ha pulsado up?
while(!input(PIN_C4)){}    //elimina rebotes
day++;    //SI -> incremento day
switch(day){    //limites...
case 0x0A:   day=0x10;break;
case 0x1A:   day=0x20;break;
case 0x2A:   day=0x30;break;
case 0x32:   day=0x01;
}    //...day
printf(lcd_putc,"\fConf.Dias:\nFecha: %2X/%2X/%2X",day,mth,year);   

//muestra por lcd day
}
}while(input(PIN_C5));
while(!input(PIN_C5)){}    //elimina rebotes
}
///FUNCION CONFIGURA MES
void mes(void){
printf(lcd_putc,"\fConf.Mes:\nFecha: %2X/%2X/%2X",day,mth,year);   //muestra por lcd
do{
if(!input(PIN_C4)){    //¿se ha pulsado up?
while(!input(PIN_C4)){}    //elimina rebotes
mth++;    //SI -> incremento mth
switch(mth){    //limites...
case 0x0A:   mth=0x10;break;
case 0x13:   mth=0x01;
}    //...mth
printf(lcd_putc,"\fConf.Mes:\nFecha: %2X/%2X/%2X",day,mth,year);   //muestra por lcd
}
}while(input(PIN_C5));
while(!input(PIN_C5)){}    //elimina rebotes
}
///FUNCION CONFIGURA AÑOS
void anio(void){
printf(lcd_putc,"\fConf.Anio:\nFecha: %2X/%2X/%2X",day,mth,year);   //muestra por lcd
do{
if(!input(PIN_C4)){    //¿se ha pulsado up?
while(!input(PIN_C4)){}    //elimina rebotes
year++;    //SI -> 1incremento mth
switch(year){    //limites...
case 0x0A:   year=0x10;break;
case 0x1A:   year=0x20;break;
case 0x2A:   year=0x30;break;
case 0x3A:   year=0x40;break;
case 0x4A:   year=0x50;break;
case 0x5A:   year=0x60;break;
case 0x6A:   year=0x70;break;
case 0x7A:   year=0x80;break;
case 0x8A:   year=0x90;break;
case 0x9A:   year=0x00;
}    //...year
printf(lcd_putc,"\fConf.Anio:\nFecha: %2X/%2X/%2X",day,mth,year);   //muestra por lcd
}
}while(input(PIN_C5));
while(!input(PIN_C5)){}    //elimina rebotes
}
///FUNCION BEEP
void beep(void){
output_high(PIN_A3);   //activa zumbador
delay_ms(50);
output_low(PIN_A3);    //desactiva zumbador
}}}
   }}
[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 2:06 pm     Reply with quote

It doesn't compile because your braces are all mis-matched.
You have too many braces in the wrong place.
Clean up the formatting of your routines. Carefully place all braces
and look at the matching brace.

If you're using MPLAB, you can select (highlight) a brace, then right-click
and select the Advanced menu, and select Match. Then it will show the
matching brace in your program. This can help you to find mistakes.

Basically, don't ever do braces like this:
Code:

}}}
   }}

This is a mess, and will cause endless problems.
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Fri Apr 19, 2013 2:26 pm     Reply with quote

I do it this way:-

Each closing } brace appears immediately below its opening { brace with white space between.
That way, it's usually obvious where the problem is.

Code:
void main(void)
{
  code here level 1;
  {
     code here level 2;
     more code level 2;
  }
  more code level 1;
  even more level 1;
}

Structure and flow are now much clearer!
Makes no difference now in English, Spanish, French, .............
I'm not even going to attempt to decipher your original effort.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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