hi, i read on the pic16f84 manual and learnt that:
An overflow (FFh - 00h) in TMR0 will set flag bit T0IF (INTCON<2>). The interrupt can be enabled/disabled by setting/clearing enable bit T0IE (INTCON<5>).i am still not able to apply this information to my code in setting the prescaler and the clock source.HELP!
here is the code i am working on.
#include <htc.h>
#include "timer.h"
#ifdef XT
__CONFIG(XT&PWRTEN&WDTDIS); // config XT
#else
__CONFIG(0x3ff1); // config XT
#define OPTION OPTION_REG
#endif
bit GeyserFlag;
extern void cput(unsigned char c);
extern void scroll(const char *mess, unsigned char ntimes);
extern void display(const char *message);
extern void clrscr(void);
extern char choice(const char *const *menu);
extern char getch(void);
extern void delay(unsigned char time);
extern char choice(const char *const *fmenu);
extern char sbuf[15];
extern char line[13];
extern unsigned char pulses;
const char *const menu1[]={
"--SET TIME--",
"--VIEW TIME--",0};
main()
{
INTCON=0x20; // TMR0 allowed to interrupt
OPTION=0x07; // prescaler 1:128 to TMR0, enable pullup resistors on PORTA
TRISB=0x00; // RB7 is input RB6:RB0 are inputs
TRISA=0x07; // port A RA2:RA0 input
pulses=0;
GIE=1; // enable all interrputs
relayoff();
RW0_HIGH(); RW1_HIGH(); // hold WR high to prevent writing to display
TRISA=0x00;
char GeyserOffTime[4];
char GeyserOnTime[4];
char CurrentTime[4];
if(GeyserFlag)
{
if(strcmp(GeyserOffTime, CurrentTime) != 0);//check if it is time to turn OFF
{
GeyserFlag = 0;
relayoff();
}//end if
}//end if
else
{ //if Flag is off: ie Geyser is OFF
if(strcmp(GeyserOnTime, CurrentTime) != 0);//check if it is time to turn it ON
{
relayon();
GeyserFlag = 1;
}//end if
}//end else
unsigned char i,j;
int State,e;
enum State {state_0,state_1,state_2};
enum Event {mode,select,set};
void scrolling();
{
printf("make a choice by pressing select");
}
void do_nothing();
{
printf("Dont bother");
}
void present_choice_on_screen();
{
printf("present choice on screen");
}
void perform_the_choice();
{
printf("do menu[j] ");
}
State = state_0;
/*eventQueue[EVENT_QUEUE_SIZE] = {mode,select,set};
int eventIndex = 0;
for(eventIndex<EVENTS_COUNT;eventIndex++)
EVENT evt = eventQueue[eventIndex];*/
switch(State)
{
case state_0:
switch(e)
{
case select:
{
do_nothing();
break;
}
case set:
{
do_nothing();
break;
}
case mode:
{
State = state_1;
scrolling();
break;
}
}
break;
case state_1:
switch(e)
{
case select:
{
State = state_2;
present_choice_on_screen();
break;
}
case set:
{
do_nothing();
break;
}
case mode:
{
do_nothing();
break;
}
}
break;
case 2:
switch(e)
{
case select:
{
perform_the_choice();
break;
}
case set:
{
do_nothing();
break;
}
case mode:
{
do_nothing();
break;
}
}
break;
}
}