georgetwo
Member
Hi guys,
yesterday i started working on a project which must involve at least 2 timers and i wanted to use pic18f4550, the datasheet tells me about high and low priority, i placed the timers at high priority. I followed the datasheet and made a test code for only timer0. But it didn"t work. I realy need your help. Im using mikro c for pic , here is what i have done:
unsigned char george = 0;
void interrupt(){
if(intcon.tmr0if){
george++;
intcon.tmr0if = 0;
}
if(pir1.tmr1if){
pir1.tmr1if = 0;
}
if(pir1.tmr2if){
pir1.TMR2IF = 0;
}
}
void configuration(void) {
trisb = 0;
portb = 0x0f;
// set internal oscillator to 8Mhz
osctune.tun4 = 0;
osctune.tun3 = 1;
osctune.tun2 = 1;
osctune.tun1 = 1;
osctune.tun0 = 1;
//======== enable timer 0 interrupt and set as hi priority=================//
t0con = 0b11010101 ;
intcon.tmr0if = 0;
intcon.tmr0ie = 1;
intcon.TMR0IP = 1;
/*//========enable timer 1 interrupt and set as hi priority===================//
t1con.rd16 = 1;
t1con.TMR1CS = 0;
t1con.T1CKPS1 = 1;
t1con.T1CKPS0 = 1;
t1con.tmr1on = 1;
pie1.TMR1IE = 1;
ipr1.TMR1IP = 1;
//========enable timer 2 interrupt and set as hi priority===================//
t2con.t2ckps1 = 1;
t2con.t2ckps0 = 0;
t2con.tmr2on = 1;
pie1.TMR2IE = 1;
ipr1.TMR2IP = 1;
//======= enable global and peripheral int.=================================//
*/
intcon.peie = 1;
intcon.gie = 1;
intcon.gieh = 1;
}
void main(){
configuration();
while(1){
if (george == 100){
portb ++;
george = 0;
}
}
}
yesterday i started working on a project which must involve at least 2 timers and i wanted to use pic18f4550, the datasheet tells me about high and low priority, i placed the timers at high priority. I followed the datasheet and made a test code for only timer0. But it didn"t work. I realy need your help. Im using mikro c for pic , here is what i have done:
unsigned char george = 0;
void interrupt(){
if(intcon.tmr0if){
george++;
intcon.tmr0if = 0;
}
if(pir1.tmr1if){
pir1.tmr1if = 0;
}
if(pir1.tmr2if){
pir1.TMR2IF = 0;
}
}
void configuration(void) {
trisb = 0;
portb = 0x0f;
// set internal oscillator to 8Mhz
osctune.tun4 = 0;
osctune.tun3 = 1;
osctune.tun2 = 1;
osctune.tun1 = 1;
osctune.tun0 = 1;
//======== enable timer 0 interrupt and set as hi priority=================//
t0con = 0b11010101 ;
intcon.tmr0if = 0;
intcon.tmr0ie = 1;
intcon.TMR0IP = 1;
/*//========enable timer 1 interrupt and set as hi priority===================//
t1con.rd16 = 1;
t1con.TMR1CS = 0;
t1con.T1CKPS1 = 1;
t1con.T1CKPS0 = 1;
t1con.tmr1on = 1;
pie1.TMR1IE = 1;
ipr1.TMR1IP = 1;
//========enable timer 2 interrupt and set as hi priority===================//
t2con.t2ckps1 = 1;
t2con.t2ckps0 = 0;
t2con.tmr2on = 1;
pie1.TMR2IE = 1;
ipr1.TMR2IP = 1;
//======= enable global and peripheral int.=================================//
*/
intcon.peie = 1;
intcon.gie = 1;
intcon.gieh = 1;
}
void main(){
configuration();
while(1){
if (george == 100){
portb ++;
george = 0;
}
}
}