Problem : Into "lowlevel/timer.h", despite it's possible, there is no PS0_1/1 for TMR0.
TMR0 shares its prescaler with WDT this way :
- When TMR0 uses the prescaler, WDT is 1/1.
- When WDT uses the prescaler, TMR0 is 1/1.
If we want to make TMR0 1/1, we have to assign the prescaler to the WDT.
But "timer.h" does not allow that.
Here is how PS0_1/1 could be added to "timer.h" :
'-----------------------------------
#define PS0_1/1 128
' When bit 7 of TMR0Pres is set, this means that
' we want to assign the prescaler to the WDT instead.
' Thus, TMR0 will be 1/1, and we can use PS0_1/1
' in combination with constants below to config the
' prescaler for the WDT.
heh!
I alread made this trick when I want to initialise timer wit prescaler 1/1
when I analised asm code, I found that code ir really bug for this simpe procedure.
Insread to use PS0_1/1 I jus simply use two asm commands for my PIC16F84a:
movlw b'11001111'
option_reg
with this two commands i am setting lot of things on my uC:
bit7: disable pull-up on portB (I don' n neet this on my project)
bit6: interrupt when PortB.0 goes high (I don' n neet this on my project)
bit5: timer clock from oscillator, not form external pin.
bit4: timer increment when porta.4 goes from 1 to 0 (I don' n neet this on my project)
bit3: prescaler goes to watchdog
bit2 to bit 0: prescaler contsatan (see datasheet)
isn't this great?
You can save lot of program memory with this.
see your uC datasheet for opton_reg details.
Remember: GCbasic iz good when You just want to make your project algorythm.
To get you algorythm wotk correctly, It is good when You know Your uC hardware and asm, because GCbasic also have bugs.
I will contribute software RS-232 bit banging code for PIC16F84a soon.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Problem : Into "lowlevel/timer.h", despite it's possible, there is no PS0_1/1 for TMR0.
TMR0 shares its prescaler with WDT this way :
- When TMR0 uses the prescaler, WDT is 1/1.
- When WDT uses the prescaler, TMR0 is 1/1.
If we want to make TMR0 1/1, we have to assign the prescaler to the WDT.
But "timer.h" does not allow that.
Here is how PS0_1/1 could be added to "timer.h" :
'-----------------------------------
#define PS0_1/1 128
' When bit 7 of TMR0Pres is set, this means that
' we want to assign the prescaler to the WDT instead.
' Thus, TMR0 will be 1/1, and we can use PS0_1/1
' in combination with constants below to config the
' prescaler for the WDT.
#define PS0_1/1_WDT 0
#define PS0_1/2_WDT 1
#define PS0_1/4_WDT 2
#define PS0_1/8_WDT 3
#define PS0_1/16_WDT 4
#define PS0_1/32_WDT 5
#define PS0_1/64_WDT 6
#define PS0_1/128_WDT 7
' ---------- Modified SInitTimer0 :
Sub SInitTimer0
OPTION_REG = OPTION_REG AND 192
if TMR0Pres >= 128 then
SET OPTION_REG.PSA ON ' assign prescaler to WDT
else
SET OPTION_REG.PSA OFF ' assign prescaler to TMR0
end if
if TMR0Source = Osc THEN SET OPTION_REG.T0SE OFF
if TMR0Source = Ext THEN SET OPTION_REG.T0SE ON
clrwdt
OPTION_REG = OPTION_REG OR (TMR0Pres AND 7)
End Sub
'---------------------------------------------------
yg2f
note :
This applies to PIC (at least 12f675 and 16f87x).
About AVR, I don't know.
heh!
I alread made this trick when I want to initialise timer wit prescaler 1/1
when I analised asm code, I found that code ir really bug for this simpe procedure.
Insread to use PS0_1/1 I jus simply use two asm commands for my PIC16F84a:
movlw b'11001111'
option_reg
with this two commands i am setting lot of things on my uC:
bit7: disable pull-up on portB (I don' n neet this on my project)
bit6: interrupt when PortB.0 goes high (I don' n neet this on my project)
bit5: timer clock from oscillator, not form external pin.
bit4: timer increment when porta.4 goes from 1 to 0 (I don' n neet this on my project)
bit3: prescaler goes to watchdog
bit2 to bit 0: prescaler contsatan (see datasheet)
isn't this great?
You can save lot of program memory with this.
see your uC datasheet for opton_reg details.
Remember: GCbasic iz good when You just want to make your project algorythm.
To get you algorythm wotk correctly, It is good when You know Your uC hardware and asm, because GCbasic also have bugs.
I will contribute software RS-232 bit banging code for PIC16F84a soon.