Winch
Member
Dear all,
Can anyone tell me what is wrong with this code?
I try to create a time delay of one minute. Instead, I get three seconds?
I can not figure out the error?
I use the software Oshonsoft! (basic)
Can anyone tell me what is wrong with this code?
I try to create a time delay of one minute. Instead, I get three seconds?
I can not figure out the error?
I use the software Oshonsoft! (basic)
Code:
'DEVICE 12F675
Define CONFIG = 0x3184
AllDigital 'alle ports digital
'parameters analoge ingang.
Define ADC_CLOCK = 3 'resolutie 8 bits
Define ADC_SAMPLEUS = 50 'sample time 5
'poortnamen
Symbol buzzer = GPIO.2 'BUZZER is connected to port GPIO.2
Symbol irled = GPIO.4 'IR LED is connected to port GPIO.4
Symbol led = GPIO.5 'LED is connected to port GPIO.5
'variabelen declareren
Dim spanning As Byte 'voltage as variable "Byte" (here the measured analog value)
Dim var_timer As Byte 'variable "TIMER" value "As Byte"
Dim timer_limite As Byte '"TIMER" limite "As Byte"
Dim timer As Byte 'higher variable timer setting "As Byte"
Dim puls As Bit 'puls is turned as "1"
Dim puls_2 As Bit 'puls_2 is turned as "1"
INTCON.GIE = 0 'Disables all unmasked interrupts make sure by start that Interrupt = 0
'543210
GPIO = %000000 'outputs at start are low-level
TRISIO = %001011 'GPIO.0 is set as input, GPIO.2, GPIO,4 en GPIO.5 is set as output
'76543210
ADCON0 = %00000001 'bit0 as a/d geselecteerd, CHS1:CHS0 bit 3-2 are selected as AN0
ANSEL = %00000001 'ANS0 (leg 7) is set as "analog input" connected the IR FILTER
'The INTCON register is a readable and writable register, which contains the various Enable And flag bits For TMR0 register overflow,
'GPIO port change And external GP2 / int pin interrupts.
INTCON.GIE = 1 'Enables all unmasked interrupts
INTCON.T0IE = 1 'Enables the TMR0 interrupt (TMR0 Overflow Interrupt Enable bit)
INTCON.T0IF = 1 'TMR0 register has overflowed (must be cleared in software)
'The OPTION register is a readable And writable register, which contains various control bits To configure:
'TMR0/wdt prescaler 'external GP2/int Interrupt 'TMR0 'weak pull - ups On GPIO
OPTION_REG.INTEDG = 0 'Interrupt on falling edge of GP2/INT pin
OPTION_REG.T0CS = 0 'Internal instruction cycle clock (CLKOUT)
OPTION_REG.T0SE = 0 'Increment on low-to-high transition on GP2/T0CKI pin
OPTION_REG.PSA = 0 'Prescaler is assigned to the TIMER0 module
OPTION_REG.PS0 = 0 'Set the prescaler
OPTION_REG.PS1 = 1 'to increment TMR0
OPTION_REG.PS2 = 1 'every 128th instruction cycle
TMR0 = 0 'Clear TMR0 initially, (reset de timer0 module register)
var_timer = 0 'variable waarde van de timer is 0
timer = 0 'set timer to 0
run:
timer_limite = 61 'intern klok (1mhz / (128 * 128)) give pulse afther every 1 seconden
If var_timer > timer_limite Then 'when var_timer is greater than timer_limite (61) than ...
var_timer = 0 'set var_timer back to 0
puls = 1
Endif
If puls = 1 Then
timer = timer + 1 'increase timer by 1
If timer > 60 Then led = 1 'if timer is greater then 60 then.....
Endif
Goto run
End 'end program
'Interrupt
On Interrupt 'Interrupt timer
Save System 'Save
var_timer = var_timer + 1 'increment var_timer
INTCON.T0IF = 0 'clear Interrupt flag
Resume 'jump back where it started