7 segment display
Posted: Mon Feb 04, 2013 3:18 pm
Hy
I have a HP488 development board with PIC16F88 mcu.
I try to make a program who count from 0 to 9999 with a delay using Timer TMR0.
My problem is I am not able to make this work.
The program must do the next tasks : count from 0 to 9 --> digit 3 and when it reaches 9 must enable digit 2.
If the count it reaches to 99 must enable digit 3 and so on.
I know how to enable the digits, i read it elctrical drawings. I failed when I try to implement it.
Can somebody give me some tips.
Look at my code.
Thank you.
#include <system.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
void setup_hardware(void)
{
trisb = 0x00;
trisa = 0xf0;
intcon = 0b10100000;
option_reg = 0b00000111;
}
unsigned char patterns[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x83, 0xf8, 0x80, 0x98};
unsigned char led_counter = 0;
unsigned char led_patterns[4] = {0x08, 0x0C, 0x0E, 0x0F};
unsigned char led = 0;
void display(void)
{
porta = 0;
portb = patterns[led_counter++];
porta = led_patterns[led];
if (led_counter > 9)
led_counter = 0;
}
void display_digit(unsigned char digit, unsigned char pos)
{
led_patterns[pos] = patterns[digit] ;
}
unsigned char counter = 0;
void interrupt(void)
{
if(intcon & 0x04)
{
clear_bit( intcon, 2 );
counter++;
if(counter == 15)
{
counter = 0;
display();
}
}
}
void main ( void )
{
setup_hardware() ;
while(1)
{
}
}
I have a HP488 development board with PIC16F88 mcu.
I try to make a program who count from 0 to 9999 with a delay using Timer TMR0.
My problem is I am not able to make this work.
The program must do the next tasks : count from 0 to 9 --> digit 3 and when it reaches 9 must enable digit 2.
If the count it reaches to 99 must enable digit 3 and so on.
I know how to enable the digits, i read it elctrical drawings. I failed when I try to implement it.
Can somebody give me some tips.
Look at my code.
Thank you.
#include <system.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG, _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC & _LVP_OFF
void setup_hardware(void)
{
trisb = 0x00;
trisa = 0xf0;
intcon = 0b10100000;
option_reg = 0b00000111;
}
unsigned char patterns[10] = {0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x83, 0xf8, 0x80, 0x98};
unsigned char led_counter = 0;
unsigned char led_patterns[4] = {0x08, 0x0C, 0x0E, 0x0F};
unsigned char led = 0;
void display(void)
{
porta = 0;
portb = patterns[led_counter++];
porta = led_patterns[led];
if (led_counter > 9)
led_counter = 0;
}
void display_digit(unsigned char digit, unsigned char pos)
{
led_patterns[pos] = patterns[digit] ;
}
unsigned char counter = 0;
void interrupt(void)
{
if(intcon & 0x04)
{
clear_bit( intcon, 2 );
counter++;
if(counter == 15)
{
counter = 0;
display();
}
}
}
void main ( void )
{
setup_hardware() ;
while(1)
{
}
}