Ik heb timer0 gebruikt voor de interrupt. De prescaler staat op 256 In het TMR0 register steek ik telkens 128. Dan zou ik volgens mijn berekening op 25 interupts per seconden komen.
3276800/4*256*128*x=1sec
(x = aantal interrupts)
3276800/4*256*128*25=1sec
Mijn test code
Code: Selecteer alles
Device 16F877A
Config WDT_Off, PWRTE_ON, XT_OSC , PWRTE_ON, lvp_off
XTAL 3',2768 MHz
ALL_DIGITAL true
'Lcd declaraties
Symbol Lengte = 16
Symbol Regels = 2
Declare LCD_DTPIN PORTD.4
Declare LCD_ENPIN PORTD.1
Declare LCD_RSPIN PORTD.0
Declare LCD_INTERFACE 4
Declare LCD_LINES Regels
'Knoppen
Symbol Knop1 = PORTE.2
Symbol Knop2 = PORTA.0
Symbol Knop3 = PORTA.4
Symbol Knop4 = PORTC.0
Symbol Knop5 = PORTA.1
Symbol Knop6 = PORTA.5
Symbol Knop7 = PORTC.1
Symbol Knop8 = PORTA.2
Symbol Knop9 = PORTE.0
Symbol Knop0 = PORTA.3
Symbol Knopenter = PORTE.1
Symbol Knopback = PORTC.2
Symbol Back = 10
Symbol Enter = 11
Dim Knop As Byte
Dim Uren10 As Byte
Dim Uren1 As Byte
Dim Min10 As Byte
Dim Min1 As Byte
'Algemeen
Dim Index As Byte
Dim intAan As Bit
Dim temp As Byte
Dim initbit As Bit
'Leds
Symbol rij0 = PORTC.7
Symbol rij1 = PORTC.6
Symbol rij2 = PORTC.5
Symbol rij3 = PORTC.4
Symbol rij4 = PORTD.3
Symbol rij5 = PORTD.2
Symbol ledKolom = PORTB
Dim ledTabel[6] As Byte
TRISB = 0
'Tijden
Dim Uren As Byte
Dim Minuten As Byte
Dim Seconden As Byte
Dim Tijd As DWord
Dim LedTijd As Word
'Interupt
Symbol T0IE = INTCON.5 ' TMR0 Overflow Interrupt Enable
Symbol T0IF = INTCON.2 ' TMR0 Overflow Interrupt Flag
Symbol GIE = INTCON.7 ' Global Interrupt Enable
Symbol PS0 = OPTION_REG.0 ' Prescaler ratio bit-0
Symbol PS1 = OPTION_REG.1 ' Prescaler ratio bit-1
Symbol PS2 = OPTION_REG.2 ' Prescaler ratio bit-2
Symbol PSA = OPTION_REG.3 ' Prescaler Assignment (1=assigned to WDT 0=assigned to oscillator)
Symbol T0CS = OPTION_REG.5 ' Timer0 Clock Source Select (0=Internal clock 1=External PORTA.4)
'3276800/4*256*128*25=1sec
GIE = 0 ' Turn off global interrupts
PSA = 0 ' Assign the prescaler to external oscillator
PS0 = 1 ' Set the prescaler
PS1 = 1 ' to increment TMR0
PS2 = 1 ' every 256th instruction cycle
T0CS = 0 ' Assign TMR0 clock to internal source
TMR0 = 128 ' Clear TMR0 initially
T0IF = 0
T0IE = 1 ' Enable TMR0 overflow interrupt
GIE = 1 ' Enable global interrupts
Clear
Cls
Dim bla As Word
hier:
'****************************************************************
High rij0
PORTB = 0
main:
Print At 1, 1, DEC2 Minuten, ":", DEC2 Seconden
DelayMS 500
GoTo main
ON_HARDWARE_INTERRUPT GoTo Interupt
GoTo hier
Interupt:
If T0IF = 1 Then
T0IF = 0
TMR0 = 128
Inc Index
If Index = 26 Then
Index = 0
Toggle PORTB.0
Inc Seconden
If Seconden = 60 Then
Seconden = 0
Inc Minuten
EndIf
EndIf
EndIf
Context Restore ' Restore the registers and exit the interrupt
EndZiet er soms iemand waarom het fout gaat?
