WStevens_sa
Member level 2
- Joined
- Jan 5, 2011
- Messages
- 47
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- South Africa
- Activity points
- 1,695
Hi all
My project is as follows. PICF877 programmed to be a RTC using TMR0 with prescaler for 1 second delay which displays day and time on a 2 x 16 LCD as "MON 00:00:00. RC0 sets hours which works and RC1 is supposed to set the minutes but does not work.
Where have I gone wrong. RC1 is not triggering "if (Button(&PORTC, 1, 1, 1)) "
My project is as follows. PICF877 programmed to be a RTC using TMR0 with prescaler for 1 second delay which displays day and time on a 2 x 16 LCD as "MON 00:00:00. RC0 sets hours which works and RC1 is supposed to set the minutes but does not work.
Where have I gone wrong. RC1 is not triggering "if (Button(&PORTC, 1, 1, 1)) "
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// VARIABLES FOR LCD
char* txt1;
int count;
int shiftcount=0;
int tic = 0;
int msec=0;
int timer_set = 0;
// INTERRUPT VARIABLES
unsigned int counter = 0 ;
unsigned int seconds = 0, minutes = 0, hours = 0, days = 0;
char* weekdays[7] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
// INTERRUPT RTC
void interrupt(void) {
if(T0IF_bit == 1){ // Check for interrupt flag
T0IF_bit=0; //Reset flag
counter++ ;
if(counter > 15625){ // 1 sec 16 Mhz crystal = 16000000 / 4 / 256 =15625
counter = 0 ;
seconds++ ;
if(seconds == 60){
seconds = 0 ;
minutes++ ;
if(minutes == 60){
minutes = 0 ;
hours++ ;
if(hours == 24){
hours = 0 ;
days++;
if (days == 7){
days = 0;
}
}
}
}
}
}
}
void main(){
//LCD
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_out(1,7,":");
Lcd_out(1,10,":");
//TMR0
OPTION_REG = 8;
GIE_bit = 1; //Enable Global Interrupt
T0IF_bit = 0; //Clear interrupt flag
T0IE_bit = 1; //Enable TMR0 interrupt
PEIE_bit = 1; //Peripheral Interrupt Enable bit
//PUSH BUTTON SETTINGs
TRISA = 0; //PortA all outputs
PORTA = 0;
TRISC = 1; // Configure PORTC as inputs
PORTC = 0; // Initial PORTC value
// Lcd_Chr(1,1,48+9); // // Only from 0 to 9. Need to use shift registerto
while(1){
//SECONDS
Lcd_Chr(1,12,48+(seconds % 10)); // seconds counter LSB
Lcd_Chr(1,11,48+((seconds /10) % 10)); //Seconds counter MSB
//MINUTES
Lcd_Chr(1,9,48+(minutes % 10)); // minutes counter LSB
Lcd_Chr(1,8,48+((minutes /10) % 10)); //minutes counter MSB
//HOURS
Lcd_Chr(1,6,48+(hours % 10)); // hours counter LSB
Lcd_Chr(1,5,48+((hours /10) % 10)); // hours counter MSB
//DAYS
Lcd_out(1,1,weekdays[days]); // days of the week
//PUSHBUTTON INPUT HOURS RC0_BIT
if (Button(&PORTC, 0, 1, 1)) {
hours++;
Delay_ms(100); // Adjust counting time when button depressed
if (hours ==24) {hours=0;}
}
//PUSHBUTTON INPUT MINUTES RC1_BIT
if (Button(&PORTC, 1, 1, 1)) {
minutes++;
Delay_ms(100); // Adjust counting time when button depressed
if (minutes ==60) {minutes=0;}
}
}
}