GreenBeret
New Member
I am facing some problem while reading input through PORTB in 16F72 PIC.
I wrote a simple code which shows a number between 0-9 in a seven-segment. When i press button connected to RB5, then number should increment to a different number. It works fine in Simulator. But when I tried in PIC, it shows digit 8, and have a flickering too....
Below given is my source code written in HiTech C. Please help. I am stuck with this problem for a long perios....
//include file
#include <pic.h>
//16F72 configuration word according to the features required.
__CONFIG(0x3FB1);
int i;
// This macro is to make a delay after showing a digit in a segment.
#define my_delay() for ( i = 0; i <= 20; i++ );
void showNumber ( unsigned char *num )
{
switch ( (*num) )
{
case 0:
PORTC = 0b11111100;
PORTB = 0b00000000;
break;
case 1:
PORTC = 0b00011000;
PORTB = 0b00000000;
break;
case 2:
PORTC = 0b01101100;
PORTB = 0b00000001;
break;
case 3:
PORTC = 0b00111100;
PORTB = 0b00000001;
break;
case 4:
PORTC = 0b10011000;
PORTB = 0b00000001;
break;
case 5:
PORTC = 0b10110100;
PORTB = 0b00000001;
break;
case 6:
PORTC = 0b11110100;
PORTB = 0b00000001;
break;
case 7:
PORTC = 0b00011100;
PORTB = 0b00000000;
break;
case 8:
PORTC = 0b11111100;
PORTB = 0b00000001;
break;
case 9:
PORTC = 0b10111100;
PORTB = 0b00000001;
break;
case 10:
PORTC = 0b0;
PORTB = 0b0;
PORTA = 0b0;
break;
}
}
//main function
void main ( void )
{
unsigned int noShow = 10;
unsigned int temp = 0;
unsigned long swith_1_Count = 0;
unsigned int flag1 = 0;
TRISB = 0b00100000;
TRISA = 0x00;
TRISC = 0x00;
PORTC = 0;
PORTB = 0;
PORTA = 0;
while ( 1 )
{
if ( ( PORTB & 0b00100000 ) == 0b00100000 )
{
temp = ( temp +1 ) % 10;
}
PORTA = 0b00000001;
showNumber(&temp);
my_delay();
}
}
I wrote a simple code which shows a number between 0-9 in a seven-segment. When i press button connected to RB5, then number should increment to a different number. It works fine in Simulator. But when I tried in PIC, it shows digit 8, and have a flickering too....
Below given is my source code written in HiTech C. Please help. I am stuck with this problem for a long perios....
//include file
#include <pic.h>
//16F72 configuration word according to the features required.
__CONFIG(0x3FB1);
int i;
// This macro is to make a delay after showing a digit in a segment.
#define my_delay() for ( i = 0; i <= 20; i++ );
void showNumber ( unsigned char *num )
{
switch ( (*num) )
{
case 0:
PORTC = 0b11111100;
PORTB = 0b00000000;
break;
case 1:
PORTC = 0b00011000;
PORTB = 0b00000000;
break;
case 2:
PORTC = 0b01101100;
PORTB = 0b00000001;
break;
case 3:
PORTC = 0b00111100;
PORTB = 0b00000001;
break;
case 4:
PORTC = 0b10011000;
PORTB = 0b00000001;
break;
case 5:
PORTC = 0b10110100;
PORTB = 0b00000001;
break;
case 6:
PORTC = 0b11110100;
PORTB = 0b00000001;
break;
case 7:
PORTC = 0b00011100;
PORTB = 0b00000000;
break;
case 8:
PORTC = 0b11111100;
PORTB = 0b00000001;
break;
case 9:
PORTC = 0b10111100;
PORTB = 0b00000001;
break;
case 10:
PORTC = 0b0;
PORTB = 0b0;
PORTA = 0b0;
break;
}
}
//main function
void main ( void )
{
unsigned int noShow = 10;
unsigned int temp = 0;
unsigned long swith_1_Count = 0;
unsigned int flag1 = 0;
TRISB = 0b00100000;
TRISA = 0x00;
TRISC = 0x00;
PORTC = 0;
PORTB = 0;
PORTA = 0;
while ( 1 )
{
if ( ( PORTB & 0b00100000 ) == 0b00100000 )
{
temp = ( temp +1 ) % 10;
}
PORTA = 0b00000001;
showNumber(&temp);
my_delay();
}
}