Skip to content

Instantly share code, notes, and snippets.

@prasant1010
Created May 16, 2017 09:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prasant1010/048c8e22bcbe8bac67b6f1f2e5283d95 to your computer and use it in GitHub Desktop.
Save prasant1010/048c8e22bcbe8bac67b6f1f2e5283d95 to your computer and use it in GitHub Desktop.
#include "Display_Utils.h"
unsigned short shifter, portb_index;
unsigned int digit, number;
unsigned short portb_array[4];
void interrupt() {
PORTA = 0; // Turn off all 7seg displays
PORTB = portb_array[portb_index]; // bring appropriate value to PORTD
PORTA = shifter; // turn on appropriate 7seg. display
// move shifter to next digit
shifter <<= 1;
if (shifter > 8u)
shifter = 1;
// increment portd_index
portb_index++ ;
if (portb_index > 3u)
portb_index = 0; // turn on 1st, turn off 2nd 7seg.
TMR0L = 0; // reset TIMER0 value
TMR0IF_bit = 0; // Clear TMR0IF
}
void main() {
ADCON1 =0x0F; // Configure PORTX pins as digital
CMCON = 0x07; // comparators OFF
TRISA = 0; // Configure PORTA as output
PORTA = 0; // Clear PORTA
TRISB = 0; // Configure PORTD as output
PORTB = 0; // Clear PORTD
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler to TMR0
TMR0L = 0; // clear TMROL
digit = 0;
portb_index = 0;
shifter = 1;
number = 9980; // Initial number value
GIE_bit = 1;
TMR0IE_bit = 1;
do {
digit = number / 1000u ; // extract thousands digit
portb_array[3] = conversion(digit); // and store it to PORTD array
digit = (number / 100u) % 10u; // extract hundreds digit
portb_array[2] = conversion(digit); // and store it to PORTD array
digit = (number / 10u) % 10u; // extract tens digit
portb_array[1] = conversion(digit); // and store it to PORTD array
digit = number % 10u; // extract ones digit
portb_array[0] = conversion(digit); // and store it to PORTD array
Delay_ms(400); // one second delay
number++ ; // increment number
if (number > 9999u)
number = 0;
} while(1); // endless loop
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment