mikroc tmr0 example
Hi,
Change this line first:
if (cnt1<0x09) with if (cnt1<0xa)... but still not good...
for your inspiration:
//Declarations------------------------------------------------------------------
//--------------------------------------------------------------end-declarations
/*
* Project name:
Display_1 (The 'Hello World' example for the 7Seg. display)
* Copyright:
(c) Mikroelektronika, 2005.
* Description:
This code demonstrates how to display number on one 7-segment display
(common cathode). Display is connected to PORTB (RB0..RB7, segment A to
RB0, segment B to RB1, etc); common cathode is connected to the pin RA1 on
PORTA. Number is incremented every 1s.
* Test configuration:
MCU: P16F877A
Dev.Board: EasyPIC3
Oscillator: HS, 08.0000 MHz
Ext. Modules: -
SW: mikroC v6.0
* NOTES:
None.
*/
unsigned short i;
//-------------- Returns mask for common cathode 7-seg. display
unsigned short mask(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
} //case end
}//~
void main() {
INTCON = 0; // Disable PEIE,INTE,RBIE,T0IE
PORTA = 0;
TRISA = 0;
PORTB = 0;
TRISB = 0;
do {
for (i = 0; i<=9u; i++) {
PORTA = 0;
PORTB = mask(i);
PORTA = 2;
Delay_ms(1000);
}
} while (1); //endless loop
}//~!