Evo ti za PIC19F4620. Može da se primeni praktično na bilo koji 8-bitni.
Ovo ti broji samo u jednom smeru do vrednosti promenljive od dva bajta (65535).
Code:
#include <xc.h>
#include <stdlib.h>
#include "hd44780.h"
#include "cfg.h"
#define _XTAL_FREQ 40000000 /* Crystal frequency in MHz */
unsigned long c;
void interrupt ISR(void)
{
if(TMR1IF)
{
TMR1IF = 0;
}
}
void main(void)
{
unsigned char i;
char lcd[10];
RCON = 0b00011111;
for(i=0;i<10;i++){__delay_ms(100);}
CMCON = 0x07;
LATA = 0;
TRISA = 0xFF;
LATB = 0;
TRISB = 0xFF;
LATC = 0;
TRISC = 0xFF;
LATD = 0;
TRISD = 0xFF;
ADCON1 = 0x0F;
LATE = 0x00;
TRISE = 0x00;
OpenLCD();
ClearLCD();
TMR1L = 0;
TMR1H = 0;
T1CON = 0b10000111;
TMR1IF = 0;
TMR1IE = 1;
PEIE = 1;
GIEL = 1;
GIEH = 1;
while(1)
{
for(i=0;i<10;i++){__delay_ms(100);}
c = (unsigned long)((TMR1H << 8) + TMR1L);
ltoa(lcd, c, 10);
GotoLCD(0,0);
PutsLCD(lcd);
}
}