I am doing dual channel timer with pic16f873 microcontroller. Compiler - mikroc from Mikroelektronika. Timer schematic and pcb is ready, now i am programming microcontroller. Now clock programming is made, but code is not working. Microcontroller now must count minutes and hours and display time in four seven segments displays. But all, that these displays shows, is lighting three segments: a, d and g. Three buttons is not programmed yet. Mybe someone could help me with the code? Schematics is in .doc file. Part I of the code:
Rich (BB code):
//Quartz crystal=2.097152Mhz, ucontroller - PIC16F873
/*Configuration:
oscilator XT; code protection off; WDT disabled; power-up timer enabled;
brown-out reset enabled; low voltage programming disabled;
code protection data disabled; flash program memory write enabled;
debugger mode disabled.
*/
//variable declaration
unsigned int Clock, T1on, T1off, T2on, T2off, Display;
unsigned short int Hours, Minutes, Seconds,
Segment1, Segment2, Segment3, Segment4, WhatShow;
bit SA1Press, SA2Press, SA3Press, SA2SA3Press, HG2DpToggle, EditMode, Blackout;
void zero(){PORTC=0b00111111;} //show number 0 in display
void one(){PORTC=0b00000110;} //show number 1 in display
void two(){PORTC=0b01011011;} //show number 2 in display
void three (){PORTC=0b01001111;} //show number 3 in display
void four (){PORTC=0b01100110;} //show number 4 in display
void five (){PORTC=0b01101101;} //show number 5 in display
void six (){PORTC=0b01111101;} //show number 8 in display
void seven (){PORTC=0b00000111;} //show number 7 in display
void eight (){PORTC=0b01111111;} //show number 8 in display
void nine (){PORTC=0b01101111;} //show number 9 in display
void blank (){PORTC=0b00000000;} //show nothing in display
void Delay(){Delay_ms(5);} //delay
void InitTimer0 ()
{
// Timer0 initialisation (led blinker in Edit mode) Period = 0.125 sec (8Hz)
TMR0 = 0; // preset for timer register
OPTION_REG.PSA = 0; // prescaler is assigned to the Timer0
OPTION_REG.PS2 = 1; // Prescaler= 256
OPTION_REG.PS1 = 1;
OPTION_REG.PS0 = 1;
OPTION_REG.T0CS = 0; // TMR0 Clock Source Select bit - Internal Clock
INTCON.T0IF=0; //clear TMR0 interrupt flag
INTCON.T0IE=0; //TMR0 interrupt enable
}
void InitTimer1 ()
{
// Timer1 initialisation (Seconds counter) Period = 1 sec
T1CON.T1CKPS1 = 1; // Prescaler= 8
T1CON.T1CKPS0 = 1;
T1CON.T1OSCEN = 0; // Timer1 Oscillator disable
T1CON.TMR1CS = 0; // Timer1 Clock Source Select bit - internal clock
T1CON.TMR1ON = 1; // enable timer
TMR1H = 0; // preset for timer1 MSB register
TMR1L = 0; // preset for timer1 LSB register
PIR1.TMR1IF = 0; //clear TMR1 interrupt flag
PIE1.TMR1IE=1; //TMR1 interrupt enable
}
void InitTimer2 ()
{
//Timer2 initialisation (Display multiplexing) Period = 0.00341797 seconds
PR2 = 7; // PR2 (Timer2 Match value)
T2CON = 120; // Postscaler=16
T2CON.T2CKPS1 = 1; // Prescaler=16
T2CON.T2CKPS0 = 0;
T2CON.TMR2ON = 1; // turn timer2 on;
PIR1.TMR2IF = 0; // clear timer2 interupt flag
PIE1.TMR2IE = 1; // enable Timer2 interrupts
}
Attachments
-
1.1 MB Views: 61
Last edited: