RozzaMozza
New Member
Hello ! i need to develop a C program that displays a
counting sequence on 7 segment display Um (where Um represents U1 or U2).
The counting sequence will display the members of the set of the first 16
hexadecimal numbers H:
H = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
in ascending numerical order. When F is reached, the display should ‘roll-over’
back to 0 and the process should be repeated.
Each character in the sequence will be displayed for T seconds. This will be
accomplished by using TIMER0 to issue an interrupt every T seconds. The
occurrence of an interrupt will cause the display to be updated with the next
character in the sequence.
The display of the counting sequence will be controlled by the push-buttons PB1
and PB2. PB2 will be configured to issue an interrupt when pressed. Pressing PBi
will start the counting sequence and its display, and pressing PBj stops the
counting and display. If PBi = PB1, then PBj = PB2 and vice versa.
This is my code so far but i am unsure as to how to use the timer to make the delays instead of normal delays
counting sequence on 7 segment display Um (where Um represents U1 or U2).
The counting sequence will display the members of the set of the first 16
hexadecimal numbers H:
H = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
in ascending numerical order. When F is reached, the display should ‘roll-over’
back to 0 and the process should be repeated.
Each character in the sequence will be displayed for T seconds. This will be
accomplished by using TIMER0 to issue an interrupt every T seconds. The
occurrence of an interrupt will cause the display to be updated with the next
character in the sequence.
The display of the counting sequence will be controlled by the push-buttons PB1
and PB2. PB2 will be configured to issue an interrupt when pressed. Pressing PBi
will start the counting sequence and its display, and pressing PBj stops the
counting and display. If PBi = PB1, then PBj = PB2 and vice versa.
This is my code so far but i am unsure as to how to use the timer to make the delays instead of normal delays
Code:
#include <p18f2550.h>
#include <timers.h>
#include <delays.h>
#pragma config FOSC = INTOSCIO_EC
#pragma config WDT = OFF //watchdog Timer off
#pragma config MCLRE = OFF //Master clear off
#pragma config LVP = OFF //LVP off
#pragma interruptlow a_func1 // says that a C function a_func1 is a low priority ISR (instruction to compiler)
void timer_isr (void);
unsigned char digit[] = {0x01,0x4F,0x12,0x06,0x4C,0x24,0x20,0x0F,0x00,0x04};
#pragma code vector=0x08 // locates branch instruction at interrupt vector
//when an int occurs we go to address 8
void vector (void) // dummy function containing an unconditional jump to the ISR
{
_asm
GOTO timer_isr
_endasm
}
#pragma code
#pragma interrupt timer_isr // identifies and specifies that function timer_isr as the interrupt handler
save=PROD // saves contents of PROD register on entry to ISR, restores it on exit (contents preserved)
void timer_isr (void) // the actual interrupt handler, acknowledges the interrupt, reloads the timer and causes the digits to be displayed
{
INTCONbits.TMR0IF = 0;
PORTA = digit[3];
Delay10KTCYx(10);
}
void main(void)
{
TRISA = 0x00;
PORTA = digit[0];
OpenTimer0 (TIMER_INT_ON & T0_SOURCE_INT & T0_8BIT);
PIR1bits.ADIF=0; //clears interrupt flag in ISR to stop program responding to same interrupt multiple times
INTCONbits.GIE = 1; //enable global interrupts (always last in configuration section)
while (1);
}
unsigned char patterns [16]= // array of bit patterns
{ 0b11011110, //0
0b00000110, //1
0b11001101, //2
0b11011001, //3
0b01010011, //4.....
0b10011011,
0b10011111,
0b11010010,
0b11011111,
0b11010011,
0b11010111,
0b00011111,
0b10001110,
0b01011101,
0b10001111,
0b10000111 };
void configure_LEDS(void)
{
TRISC= 0b11101111;
TRISD= 0x00000000; // set up the tris functions
}
void display_on_Um(unsigned char display_val) // delay and patterns
{
LATD=patterns[0];
Delay10KTCYx(Delay);
LATD=patterns[1];
Delay10KTCYx(Delay);
LATD=patterns[2];
Delay10KTCYx(Delay);
LATD=patterns[3];
Delay10KTCYx(Delay);
LATD=patterns[4];
Delay10KTCYx(Delay);
LATD=patterns[5];
Delay10KTCYx(Delay);
LATD=patterns[6];
Delay10KTCYx(Delay);
LATD=patterns[7];
Delay10KTCYx(Delay);
LATD=patterns[8];
Delay10KTCYx(Delay);
LATD=patterns[9];
Delay10KTCYx(Delay);
LATD=patterns[10];
Delay10KTCYx(Delay);
LATD=patterns[11];
Delay10KTCYx(Delay);
LATD=patterns[12];
Delay10KTCYx(Delay);
LATD=patterns[13];
Delay10KTCYx(Delay);
LATD=patterns[14];
Delay10KTCYx(Delay);
LATD=patterns[15];
Delay10KTCYx(Delay);
LATD=patterns[16];
Delay10KTCYx(Delay);
}
}
}
void switch_on_Um(void)
{ LATC=0b11011111;}
void switch_off_Um(void)
{ LATC=0b11111111;
}
void display_on_Um(unsigned char display_val)
{
LATD=display_val;
}
Last edited by a moderator: