View attachment 63649View attachment 63649
#include <pic.h>
void initPORTB(void); //initialize portb
void initTMR1(void); //initialize TMR1
void interrupt TMR1INT(void); //TMR1 interrupt program
void display(void); //display program
int second=0; //counter variable
void main()
{
initPORTB(); //initialize portb
initTMR1(); //initialize TMR1
while(1){}
}
void initPORTB() //initialize PORTB
{
TRISB=0X00; //set PORTB is output
PORTB=0X00; //initialize PORTB output is 0;
}
void initTMR1()
{
T1CON&=0XC0; //set frequency ratio is 1:1,select internal clock ,close TMR1
GIE=0; //close interrupt
TMR1H=0X9E; //set TMR1 initial value=9e58H,the simulation frequency is 1MHz
TMR1L=0X58; //4*(ffff-9E58+1)=100ms
TMR1IF=0; //clear TMR1 interruption flag
TMR1IE=1; //enable TMR1 interrupt
PEIE=1; //enable Peripheral interrupt
GIE=1; //enable global interrupt
TMR1ON=1; //open TMR1
}
void interrupt TMR1INT() //TMR1 interruption program
{
GIE=0; //close interruption
TMR1IF=0; //clear interruption flag
second++; //counter add 1
display(); //display counter
TMR1H=0X9E; //reset counter initial value
TMR1L=0X58;
GIE=1; //open interruption
TMR10N=1; //open counter TMR1
}
void display()
{
int disp;
if(second>9)
{
disp++;
if(disp>9) disp=0; //out the rage of display,clear the value
second=0;
}
PORTB=(disp<<4)|second; //display
}
this is my program,I don't know where is wrong, can you help me find the mistake
#include <pic.h>
void initPORTB(void); //initialize portb
void initTMR1(void); //initialize TMR1
void interrupt TMR1INT(void); //TMR1 interrupt program
void display(void); //display program
int second=0; //counter variable
void main()
{
initPORTB(); //initialize portb
initTMR1(); //initialize TMR1
while(1){}
}
void initPORTB() //initialize PORTB
{
TRISB=0X00; //set PORTB is output
PORTB=0X00; //initialize PORTB output is 0;
}
void initTMR1()
{
T1CON&=0XC0; //set frequency ratio is 1:1,select internal clock ,close TMR1
GIE=0; //close interrupt
TMR1H=0X9E; //set TMR1 initial value=9e58H,the simulation frequency is 1MHz
TMR1L=0X58; //4*(ffff-9E58+1)=100ms
TMR1IF=0; //clear TMR1 interruption flag
TMR1IE=1; //enable TMR1 interrupt
PEIE=1; //enable Peripheral interrupt
GIE=1; //enable global interrupt
TMR1ON=1; //open TMR1
}
void interrupt TMR1INT() //TMR1 interruption program
{
GIE=0; //close interruption
TMR1IF=0; //clear interruption flag
second++; //counter add 1
display(); //display counter
TMR1H=0X9E; //reset counter initial value
TMR1L=0X58;
GIE=1; //open interruption
TMR10N=1; //open counter TMR1
}
void display()
{
int disp;
if(second>9)
{
disp++;
if(disp>9) disp=0; //out the rage of display,clear the value
second=0;
}
PORTB=(disp<<4)|second; //display
}
this is my program,I don't know where is wrong, can you help me find the mistake
Last edited: