#include <pic.h>
void main(void)
{
int tmp;
TRISB = 0b00000000;
RBPU = 0; // Use internal pullups
T0IE = 1; // Enable interrupt on TMR0 overflow
INTEDG = 1; // falling edge trigger the interrupt
INTE = 1; // enable the external interrupt
GIE = 1; // Global interrupt enable
tmp=1;
for(;;)
{
CLRWDT(); // Idly kick the dog
}
}
static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
if(tmp==1)
{
PORTD=map[i];
RB3=1;
T0IF=0;
}
else if(tmp==2)
{
PORTD=map[i];
RB3=0;
RB2=1;
T0IF=0;
}
else if(tmp==4)
{
PORTD=map[i];
RB2=0;
RB1=1;
T0IF=0;
}
else if(tmp==8)
{
PORTD=map[i];
RB1=0;
RB0,1;
T0IF=0;
}
tmp=0;
tmp=1;
}
}
#include <pic.h>
int tmp; //was local to main
char map[4]; //wasn't defined
char i; //ditto
void main(void)
{
TRISB = 0b00000000;
RBPU = 0; // Use internal pullups
T0IE = 1; // Enable interrupt on TMR0 overflow
INTEDG = 1; // falling edge trigger the interrupt
INTE = 1; // enable the external interrupt
GIE = 1; // Global interrupt enable
tmp=1;
for(;;){
CLRWDT(); // Idly kick the dog
}
}
static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
if(tmp==1)
{
PORTD=map[i];
RB3=1;
T0IF=0;
}
else if(tmp==2)
{
PORTD=map[i];
RB3=0;
RB2=1;
T0IF=0;
}
else if(tmp==4)
{
PORTD=map[i];
RB2=0;
RB1=1;
T0IF=0;
}
else if(tmp==8)
{
PORTD=map[i];
RB1=0;
RB0,1;
T0IF=0;
}
tmp=0;
tmp=1;
}
}
compiled successfully.but no output came.
That is because map[] and i are not initialized.
Mike.
#include <pic.h>
int tmp;
char i[4]={1,2,3,4};
const char map[10]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x67};
void main(void)
{
OPTION=0b01000110; //prescaler 128
TRISB=0b00000000;
TRISD=0b00000000; //port D output
T0IE = 1; // Enable interrupt on TMR0 overflow
tmp=1;
GIE = 1; // Global interrupt enable
while(1){ //loop forever
CLRWDT(); // Idly kick the dog
}
}
static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
PORTB&=0xf0; //turn off all segments
T0IF=0; //clear interrupt
if(tmp==1) //first digit
{
PORTD=map[i[0]];//put segment pattern on port D
RB0=1; //and turn on display 1
}
else if(tmp==2)
{
PORTD=map[i[1]];
RB1=1;
}
else if(tmp==3)
{
PORTD=map[i[2]];
RB2=1;
}
else if(tmp==4)
{
PORTD=map[i[3]];
RB3,1;
}
tmp++; //change to next digit
if(tmp==5) //done last digit
tmp=1; //yes so start again
}
}
When you change from digit to digit, turn off the common pin on the previous digit. ....
static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
[COLOR="red"]PORTB&=0xf0;[/COLOR] //turn off all segments
T0IF=0; //clear interrupt
if(tmp==1) //first digit
{
When you change from digit to digit, turn off the common pin on the previous digit. If you do not you can get unwanted segments illuminated. I call this ghosting but it may not be the correct use of the term
turn off all common
select segments
select common
...
turn off all common
select segments
select common
....
#include <pic.h>
int tmp;
char i[4]={1,2,3,4};
const char map[10]={
0x3f,0x06,0x5b,0x4f,0x66,
0x6d,0x7d,0x07,0x7f,0x67};
void main(void)
{
OPTION=0b01000110; //prescaler 128
TRISB=0b00000000;
TRISD=0b00000000; //port D output
TRISC=0x00;
RC0=0;
T0IE = 1; // Enable interrupt on TMR0 overflow
tmp=1;
GIE = 1; // Global interrupt enable
while(1){ //loop forever
CLRWDT(); // Idly kick the dog
}
}
static void interrupt
isr(void) // Here be interrupt function - the name is unimportant.
{
if(T0IF==1)
{
PORTB&=0xf0; //turn off all segments
T0IF=0; //clear interrupt
if(tmp==1) //first digit
{
PORTD=map[i[0]];//put segment pattern on port D
PORTB=0x00;
RB0=1; //and turn on display 1
}
else if(tmp==2)
{
PORTD=map[i[1]];
PORTB=0x00;
RB1=1;
}
else if(tmp==3)
{
PORTD=map[i[2]];
PORTB=0x00;
RB2=1;
}
else if(tmp==4)
{
PORTD=map[i[3]];
PORTB=0x00;
RB3,1;
}
tmp++; //change to next digit
if(tmp==5) //done last digit
PORTB=0x00;
tmp=1; //yes so start again
}
}
I turned of all digits at the beginning of the ISR.
I was not suggesting there was a problem with your code. Just trying to help Jimmy understand what needs to happen. But given that you have written the code for him I will step back and shut up.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?