HI all..
I am having trouble getting a character from a terminal to a variable and then continuing to run the program.
I am inexperienced so I must be doing something wrong
Here's my code:
after the red print f i wont show nothing anymore.
Really need some of your help
I am having trouble getting a character from a terminal to a variable and then continuing to run the program.
I am inexperienced so I must be doing something wrong
Here's my code:
Rich (BB code):
#include <16F874A.h>
#include <math.h>
#include <ds1306.c>
#use delay(clock=20000000)
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,parity=N, bits=8 )
int8 hour, minute, second, day, date, month, year, control;
char str[10], c;
void main()
{
printf ("inicio\r\n");
int8 hour, minute, second, day, date, month, year, control;
char str[10], c;
ds1306_init();
printf ("ds1306_init();\r\n");
ds1306_writebyte(0x8F, 0x00);
printf (" ds1306_writebyte(0x8F, 0x00);\r\n");
delay_us(10);
ds1306_writebyte(0x8F, 0x02);
printf ("ds1306_writebyte(0x8F, 0x02);\r\n");
/*printf("enter hour (0 - 23).\r\n");
hour = gets(str);
printf("enter minute (0 - 60).\r\n");
minute = gets(str);
printf("enter second (0 - 60).\r\n");
second = gets(str);
printf("enter day (1=monday, 2=tuesday, etc).\r\n");
day = gets(str);
printf("enter day of month (1 - 31).\r\n");
date = gets(str);
printf("enter month (1 - 12).\r\n");
month = gets(str);
printf("enter year 20XX (0 - 99).\r\n");
year = gets(str);*/
ds1306_settime_24hr(15, 20, 15);
ds1306_setdate(4, 23, 2, 6);
printf("Press 't' to retrieve the time and 'd' to retrieve the date.\r\n");
while(1)
{
c = getc();
printf ("%c\r\n",c);
if ((c == 't') || (c == 'T'))
{
second = bcd2bin(ds1306_readbyte(0x00));
minute = bcd2bin(ds1306_readbyte(0x01));
hour = bcd2bin(ds1306_readbyte(0x02));
printf("Time = ");
if (hour < 10)
printf("0%d:", hour);
else
printf("%d:", hour);
if (minute < 10)
printf("0%d:", minute);
else
printf("%d:", minute);
if (second < 10)
printf("0%d", second);
else
printf("%d", second);
printf("\r\n");
}
c = getc();
if ((c == 'a') || (c == 'A'))
{
second = bcd2bin(ds1306_readbyte(0x0B));
minute = bcd2bin(ds1306_readbyte(0x0C));
hour = bcd2bin(ds1306_readbyte(0x0D));
printf("Alarm time = ");
if (hour < 10)
printf("0%d:", hour);
else
printf("%d:", hour);
if (minute < 10)
printf("0%d:", minute);
else
printf("%d:", minute);
if (second < 10)
printf("0%d", second);
else
printf("%d", second);
printf("\r\n");
}
if ((c == 'd') || (c == 'D'))
{
day = bcd2bin(ds1306_readbyte(0x03));
date = bcd2bin(ds1306_readbyte(0x04));
month = bcd2bin(ds1306_readbyte(0x05));
year = bcd2bin(ds1306_readbyte(0x06));
printf("Date = ");
switch(day)
{
case 1: printf("Monday");
break;
case 2: printf("Tuesday");
break;
case 3: printf("Wednesday");
break;
case 4: printf("Thursday");
break;
case 5: printf("Friday");
break;
case 6: printf("Saturday");
break;
case 7: printf("Sunday");
break;
}
printf(", ");
if (date < 10)
printf("0%d/", date);
else
printf("%d/", date);
if (month < 10)
printf("0%d/", month);
else
printf("%d/", month);
if (year < 10)
printf("0%d", year);
else
printf("%d", year);
printf("\r\n");
}
delay_ms(10000);
printf ("end of while");
}
}
Really need some of your help