not sure where this should go, but i couldnt use the timer on my 16f1826 enhanced pic micro. the culprit was in the timer.h file, the 16f1826 has TMR1CS0 and TMR1CS1 because of the capacitive sensors being able to be used as timer inputs (or something like that) im working on modifying the code to work with this chip and will post the updated code on here for anyone interested. this code im going to post shouldnt change function of normal chips but adds the changes needed for TMR1CS0 and TMR1CS1 (i also remembered i added TMR0CS in place of T0SE for timer0, im going to check over and test any other timers on this chip before posting the code, maybe the developer would like to put this code in the updates?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This code compiled properly but I havent tested it yet on the actual chip, but here it is anyway
' Timer control routines for Great Cow BASIC'Copyright(C)2006-2009HughConsidine' This library is free software; you can redistribute it and/or'modifyitunderthetermsoftheGNULesserGeneralPublic' License as published by the Free Software Foundation; either'version2.1oftheLicense,or(atyouroption)anylaterversion.' This library is distributed in the hope that it will be useful,'butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU'LesserGeneralPublicLicenseformoredetails.' You should have received a copy of the GNU Lesser General Public'Licensealongwiththislibrary;ifnot,writetotheFreeSoftware' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'********************************************************************************'IMPORTANT:'THISFILEISESSENTIALFORSOMEOFTHECOMMANDSINGCBASIC.DONOTALTERTHISFILE'UNLESS YOU KNOW WHAT YOU ARE DOING. CHANGING THIS FILE COULD RENDER SOME GCBASIC'COMMANDSUNUSABLE!'********************************************************************************'Changes:' 10/7/2009: Added AVR support'04/11/2012:Addedsupportfor16f1826bybowlofpudding'Subroutines:'InitTimer0(Source,Prescaler)' InitTimer1 (Source, Prescaler)'InitTimer2(Prescaler,Postscaler)' InitTimer3 (Source, Prescaler)'ClearTimer(TimerNumber)' StartTimer(TimerNumber)'StopTimer(TimerNumber)'Some simpler names for the timers (use to read)#ifdef PIC '#defineTimer0TMR0DimTimer0AliasTMR0'#define Timer1 TMR1L 'Isnowafunction,needtoensurereadhappensincertainorder'#define Timer2 TMR2 Dim Timer2 Alias TMR2#endif#ifdef AVR Dim Timer0 Alias TCNT0 Dim Timer2 Alias TCNT2#endif'Sources#defineOsc1#defineExt2#defineExtOsc3'AVR prescaler settings#define PS_1 1#define PS_8 2#define PS_64 3#define PS_256 4#define PS_1024 5'Alsoworthnotinghere,'0: stop timer'6:external,clockonfalling'7: external, clock on rising#define AVR_EXT_TMR 7'Timer0prescales#definePS0_1/20#definePS0_1/41#definePS0_1/82#definePS0_1/163#definePS0_1/324#definePS0_1/645#definePS0_1/1286#definePS0_1/2567#definePS0_20#definePS0_41#definePS0_82#definePS0_163#definePS0_324#definePS0_645#definePS0_1286#definePS0_2567'Timer 1 prescales#define PS1_1/1 0#define PS1_1/2 16#define PS1_1/4 32#define PS1_1/8 48#define PS1_1 0#define PS1_2 16#define PS1_4 32#define PS1_8 48'Timer2prescales#definePS2_1/10#definePS2_1/41#definePS2_1/162#definePS2_10#definePS2_41#definePS2_162'Timer 3 prescales#define PS3_1/1 0#define PS3_1/2 16#define PS3_1/4 32#define PS3_1/8 48#define PS3_1 0#define PS3_2 16#define PS3_4 32#define PS3_8 48Function Timer1 As Word #ifdef PIC [byte]Timer1 = TMR1L Timer1_H = TMR1H #endif #ifdef AVR [byte]Timer1 = TCNT1L Timer1_H = TCNT1H #endifEnd FunctionFunction Timer3 As Word #ifdef PIC [byte]Timer3 = TMR3L Timer3_H = TMR3H #endif #ifdef AVR [byte]Timer3 = TCNT3L Timer3_H = TCNT3H #endifEnd FunctionFunction Timer4 As Word #ifdef AVR [byte]Timer4 = TCNT4L Timer4_H = TCNT4H #endifEnd FunctionFunction Timer5 As Word #ifdef AVR [byte]Timer5 = TCNT5L Timer5_H = TCNT5H #endifEnd Function'Start/Clear/StopsubsSubStartTimer(InTMRNumber)#ifdefPIC'Timer 0 always runs #ifdef Var(T1CON) If TMRNumber = 1 Then Set TMR1ON On End If #endif #ifdef Var(T2CON) If TMRNumber = 2 Then T2CON = TMR2Pres Set TMR2ON On End If #endif #ifdef Var(T3CON) If TMRNumber = 3 Then Set TMR3ON On End If #endif #endif #ifdef AVR 'Needtosetclockselectbitsto0#ifndefVar(TCCR0B)#ifdefVar(TCCR0)IfTMRNumber=0ThenTCCR0=TMR0PresEndIf#endif#endif#ifdefVar(TCCR0B)IfTMRNumber=0ThenTCCR0B=TCCR0BAnd248OrTMR0PresEndIf#endif#ifdefVar(TCCR1B)IfTMRNumber=1ThenTCCR1B=TCCR1BAnd248OrTMR1PresEndIf#endif#ifdefVar(TCCR2B)IfTMRNumber=2ThenTCCR2B=TCCR2BAnd248OrTMR2PostEndIf#endif#ifdefVar(TCCR3B)IfTMRNumber=3ThenTCCR3B=TCCR3BAnd248OrTMR3PresEndIf#endif#ifdefVar(TCCR4B)IfTMRNumber=4ThenTCCR4B=TCCR4BAnd248OrTMR4PresEndIf#endif#ifdefVar(TCCR5B)IfTMRNumber=5ThenTCCR5B=TCCR5BAnd248OrTMR5PresEndIf#endif#endifEndSubSubClearTimer(InTMRNumber)#ifdefPICIfTMRNumber=0ThenTMR0=0SInitTimer0EndIf#ifdefVar(T1CON)IfTMRNumber=1thenTMR1H=0TMR1L=0SInitTimer1EndIf#endif#ifdefVar(T2CON)IfTMRNumber=2ThenTMR2Pres=T2CONTMR2=0T2CON=TMR2PresEndIf#endif#ifdefVar(T3CON)IfTMRNumber=3thenTMR3H=0TMR3L=0SInitTimer3EndIf#endif#endif#ifdefAVR#ifdefVar(TCNT0)IfTMRNumber=0ThenTCNT0=0EndIf#endif#ifdefVar(TCNT1L)IfTMRNumber=1ThenTCNT1H=0TCNT1L=0EndIf#endif#ifdefVar(TCNT2)IfTMRNumber=2ThenTCNT2=0EndIf#endif#ifdefVar(TCNT3L)IfTMRNumber=3ThenTCNT3H=0TCNT3L=0EndIf#endif#ifdefVar(TCNT4L)IfTMRNumber=4ThenTCNT4H=0TCNT4L=0EndIf#endif#ifdefVar(TCNT5L)IfTMRNumber=5ThenTCNT5H=0TCNT5L=0EndIf#endif#endifEndSubSubStopTimer(InTMRNumber)#ifdefPIC'Timer 0 always runs If TMRNumber = 1 Then Set TMR1ON OFF End If #ifdef Var(T2CON) If TMRNumber = 2 Then Set TMR2ON OFF End If #endif #ifdef Var(T3CON) If TMRNumber = 3 Then Set TMR3ON OFF End If #endif #endif #ifdef AVR 'Needtosetclockselectbitsto0#ifdefVar(TCCR0B)IfTMRNumber=0ThenTCCR0B=TCCR0BAnd248EndIf#endif#ifdefVar(TCCR1B)IfTMRNumber=1ThenTCCR1B=TCCR1BAnd248EndIf#endif#ifdefVar(TCCR2B)IfTMRNumber=2ThenTCCR2B=TCCR2BAnd248EndIf#endif#ifdefVar(TCCR3B)IfTMRNumber=3ThenTCCR3B=TCCR3BAnd248EndIf#endif#ifdefVar(TCCR4B)IfTMRNumber=4ThenTCCR4B=TCCR4BAnd248EndIf#endif#ifdefVar(TCCR5B)IfTMRNumber=5ThenTCCR5B=TCCR5BAnd248EndIf#endif#endifEndSub'Initialise subs for individual timersSub InitTimer0(In TMR0Source, In TMR0Pres) #ifdef PIC SInitTimer0 #endif #ifdef AVR 'JustneedtobufferTMR0Pres'(And change it for external clock) If TMR0Source = Ext Then TMR0Pres = AVR_EXT_TMR End If #endifEnd SubSub SInitTimer0 OPTION_REG = OPTION_REG AND 192 SET OPTION_REG.PSA OFF'tofixfor16f1826#ifdefT0SEifTMR0Source=OscTHENSETOPTION_REG.T0SEOFFifTMR0Source=ExtTHENSETOPTION_REG.T0SEON#endif#ifndefT0SEifTMR0Source=OscTHENSETOPTION_REG.TMR0CSOFFifTMR0Source=ExtTHENSETOPTION_REG.TMR0CSON#endifclrwdtOPTION_REG=OPTION_REGORTMR0PresEndSubSubInitTimer1(InTMR1Source,InTMR1Pres)#ifdefPICSInitTimer1#endif#ifdefAVRIfTMR1Source=ExtThenTMR1Pres=AVR_EXT_TMREndIf#endifEndSubSubSInitTimer1T1CON=TMR1Pres'added for 16f1826 If TMR1Source = Ext Then #ifdef TMR1CS Set TMR1CS On #endif 'addedfor16f1826#ifndefTMR1CSSetTMR1CS1On#endifEndIfIfTMR1Source=ExtOscThen#ifdefTMR1CSSetTMR1CSOn#endif'added for 16f1826 #ifndef TMR1CS Set TMR1CS1 On #endif Set T1OSCEN On End If #endifEnd SubSub InitTimer2 (In TMR2Pres, In TMR2Post) #ifdef PIC swapf TMR2Post,F rrf TMR2Post,W andlw 120 iorwf TMR2Pres,F #endif #ifdef AVR 'SomewackyswappingofvariablenameshereIfTMR2Pres=ExtThenTMR2Post=AVR_EXT_TMREndIf#endifEndSubSubInitTimer3(InTMR3Source,InTMR3Pres)#ifdefPICSInitTimer3#endif#ifdefAVRIfTMR3Source=ExtThenTMR3Pres=AVR_EXT_TMREndIf#endifEndSubSubSInitTimer3T3CON=TMR3PresIfTMR3Source=ExtThenSetTMR3CSOnEndIfIfTMR3Source=ExtOscThenSetTMR3CSOnEndIfEndSubSubInitTimer4(InTMR4Source,InTMR4Pres)#ifdefAVRIfTMR4Source=ExtThenTMR4Pres=AVR_EXT_TMREndIf#endifEndSubSubInitTimer5(InTMR5Source,InTMR5Pres)#ifdefAVRIfTMR5Source=ExtThenTMR5Pres=AVR_EXT_TMREndIf#endifEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I tested the code I modified with a non 16f1826 chip and the way I had the "#ifndef" in there made the compile fail. I've made the required changes and it should now work with the 16f1826, and with any other chip is used to work with. I'm a beginner at C code and really really beginner at understanding ASM codes, I just used my common sense to figure these problems out.
' Timer control routines for Great Cow BASIC'Copyright(C)2006-2009HughConsidine' This library is free software; you can redistribute it and/or'modifyitunderthetermsoftheGNULesserGeneralPublic' License as published by the Free Software Foundation; either'version2.1oftheLicense,or(atyouroption)anylaterversion.' This library is distributed in the hope that it will be useful,'butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU'LesserGeneralPublicLicenseformoredetails.' You should have received a copy of the GNU Lesser General Public'Licensealongwiththislibrary;ifnot,writetotheFreeSoftware' Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA'********************************************************************************'IMPORTANT:'THISFILEISESSENTIALFORSOMEOFTHECOMMANDSINGCBASIC.DONOTALTERTHISFILE'UNLESS YOU KNOW WHAT YOU ARE DOING. CHANGING THIS FILE COULD RENDER SOME GCBASIC'COMMANDSUNUSABLE!'********************************************************************************'Changes:' 10/7/2009: Added AVR support'04/11/2012:Addedsupportfor16f1826bybowlofpudding'Subroutines:'InitTimer0(Source,Prescaler)' InitTimer1 (Source, Prescaler)'InitTimer2(Prescaler,Postscaler)' InitTimer3 (Source, Prescaler)'ClearTimer(TimerNumber)' StartTimer(TimerNumber)'StopTimer(TimerNumber)'Some simpler names for the timers (use to read)#ifdef PIC '#defineTimer0TMR0DimTimer0AliasTMR0'#define Timer1 TMR1L 'Isnowafunction,needtoensurereadhappensincertainorder'#define Timer2 TMR2 Dim Timer2 Alias TMR2#endif#ifdef AVR Dim Timer0 Alias TCNT0 Dim Timer2 Alias TCNT2#endif'Sources#defineOsc1#defineExt2#defineExtOsc3'AVR prescaler settings#define PS_1 1#define PS_8 2#define PS_64 3#define PS_256 4#define PS_1024 5'Alsoworthnotinghere,'0: stop timer'6:external,clockonfalling'7: external, clock on rising#define AVR_EXT_TMR 7'Timer0prescales#definePS0_1/20#definePS0_1/41#definePS0_1/82#definePS0_1/163#definePS0_1/324#definePS0_1/645#definePS0_1/1286#definePS0_1/2567#definePS0_20#definePS0_41#definePS0_82#definePS0_163#definePS0_324#definePS0_645#definePS0_1286#definePS0_2567'Timer 1 prescales#define PS1_1/1 0#define PS1_1/2 16#define PS1_1/4 32#define PS1_1/8 48#define PS1_1 0#define PS1_2 16#define PS1_4 32#define PS1_8 48'Timer2prescales#definePS2_1/10#definePS2_1/41#definePS2_1/162#definePS2_10#definePS2_41#definePS2_162'Timer 3 prescales#define PS3_1/1 0#define PS3_1/2 16#define PS3_1/4 32#define PS3_1/8 48#define PS3_1 0#define PS3_2 16#define PS3_4 32#define PS3_8 48Function Timer1 As Word #ifdef PIC [byte]Timer1 = TMR1L Timer1_H = TMR1H #endif #ifdef AVR [byte]Timer1 = TCNT1L Timer1_H = TCNT1H #endifEnd FunctionFunction Timer3 As Word #ifdef PIC [byte]Timer3 = TMR3L Timer3_H = TMR3H #endif #ifdef AVR [byte]Timer3 = TCNT3L Timer3_H = TCNT3H #endifEnd FunctionFunction Timer4 As Word #ifdef AVR [byte]Timer4 = TCNT4L Timer4_H = TCNT4H #endifEnd FunctionFunction Timer5 As Word #ifdef AVR [byte]Timer5 = TCNT5L Timer5_H = TCNT5H #endifEnd Function'Start/Clear/StopsubsSubStartTimer(InTMRNumber)#ifdefPIC'Timer 0 always runs #ifdef Var(T1CON) If TMRNumber = 1 Then Set TMR1ON On End If #endif #ifdef Var(T2CON) If TMRNumber = 2 Then T2CON = TMR2Pres Set TMR2ON On End If #endif #ifdef Var(T3CON) If TMRNumber = 3 Then Set TMR3ON On End If #endif #endif #ifdef AVR 'Needtosetclockselectbitsto0#ifndefVar(TCCR0B)#ifdefVar(TCCR0)IfTMRNumber=0ThenTCCR0=TMR0PresEndIf#endif#endif#ifdefVar(TCCR0B)IfTMRNumber=0ThenTCCR0B=TCCR0BAnd248OrTMR0PresEndIf#endif#ifdefVar(TCCR1B)IfTMRNumber=1ThenTCCR1B=TCCR1BAnd248OrTMR1PresEndIf#endif#ifdefVar(TCCR2B)IfTMRNumber=2ThenTCCR2B=TCCR2BAnd248OrTMR2PostEndIf#endif#ifdefVar(TCCR3B)IfTMRNumber=3ThenTCCR3B=TCCR3BAnd248OrTMR3PresEndIf#endif#ifdefVar(TCCR4B)IfTMRNumber=4ThenTCCR4B=TCCR4BAnd248OrTMR4PresEndIf#endif#ifdefVar(TCCR5B)IfTMRNumber=5ThenTCCR5B=TCCR5BAnd248OrTMR5PresEndIf#endif#endifEndSubSubClearTimer(InTMRNumber)#ifdefPICIfTMRNumber=0ThenTMR0=0SInitTimer0EndIf#ifdefVar(T1CON)IfTMRNumber=1thenTMR1H=0TMR1L=0SInitTimer1EndIf#endif#ifdefVar(T2CON)IfTMRNumber=2ThenTMR2Pres=T2CONTMR2=0T2CON=TMR2PresEndIf#endif#ifdefVar(T3CON)IfTMRNumber=3thenTMR3H=0TMR3L=0SInitTimer3EndIf#endif#endif#ifdefAVR#ifdefVar(TCNT0)IfTMRNumber=0ThenTCNT0=0EndIf#endif#ifdefVar(TCNT1L)IfTMRNumber=1ThenTCNT1H=0TCNT1L=0EndIf#endif#ifdefVar(TCNT2)IfTMRNumber=2ThenTCNT2=0EndIf#endif#ifdefVar(TCNT3L)IfTMRNumber=3ThenTCNT3H=0TCNT3L=0EndIf#endif#ifdefVar(TCNT4L)IfTMRNumber=4ThenTCNT4H=0TCNT4L=0EndIf#endif#ifdefVar(TCNT5L)IfTMRNumber=5ThenTCNT5H=0TCNT5L=0EndIf#endif#endifEndSubSubStopTimer(InTMRNumber)#ifdefPIC'Timer 0 always runs If TMRNumber = 1 Then Set TMR1ON OFF End If #ifdef Var(T2CON) If TMRNumber = 2 Then Set TMR2ON OFF End If #endif #ifdef Var(T3CON) If TMRNumber = 3 Then Set TMR3ON OFF End If #endif #endif #ifdef AVR 'Needtosetclockselectbitsto0#ifdefVar(TCCR0B)IfTMRNumber=0ThenTCCR0B=TCCR0BAnd248EndIf#endif#ifdefVar(TCCR1B)IfTMRNumber=1ThenTCCR1B=TCCR1BAnd248EndIf#endif#ifdefVar(TCCR2B)IfTMRNumber=2ThenTCCR2B=TCCR2BAnd248EndIf#endif#ifdefVar(TCCR3B)IfTMRNumber=3ThenTCCR3B=TCCR3BAnd248EndIf#endif#ifdefVar(TCCR4B)IfTMRNumber=4ThenTCCR4B=TCCR4BAnd248EndIf#endif#ifdefVar(TCCR5B)IfTMRNumber=5ThenTCCR5B=TCCR5BAnd248EndIf#endif#endifEndSub'Initialise subs for individual timersSub InitTimer0(In TMR0Source, In TMR0Pres) #ifdef PIC SInitTimer0 #endif #ifdef AVR 'JustneedtobufferTMR0Pres'(And change it for external clock) If TMR0Source = Ext Then TMR0Pres = AVR_EXT_TMR End If #endifEnd SubSub SInitTimer0 OPTION_REG = OPTION_REG AND 192 SET OPTION_REG.PSA OFF'tofixfor16f1826#ifdefT0SEifTMR0Source=OscTHENSETOPTION_REG.T0SEOFFifTMR0Source=ExtTHENSETOPTION_REG.T0SEON#endif#ifdefTMR0CS'added for 16f1826 if TMR0Source = Osc THEN SET OPTION_REG.TMR0CS OFF if TMR0Source = Ext THEN SET OPTION_REG.TMR0CS ON#endif clrwdt OPTION_REG = OPTION_REG OR TMR0PresEnd SubSub InitTimer1(In TMR1Source, In TMR1Pres) #ifdef PIC SInitTimer1 #endif #ifdef AVR If TMR1Source = Ext Then TMR1Pres = AVR_EXT_TMR End If #endifEnd SubSub SInitTimer1 T1CON = TMR1Pres If TMR1Source = Ext Then 'addedfor16f1826#ifdefTMR1CSSetTMR1CSOn#endif#ifdefTMR1CS1SetTMR1CS1On#endifEndIfIfTMR1Source=ExtOscThen#ifdefTMR1CS'added for 16f1826 Set TMR1CS On #endif 'addedfor16f1826#ifdefTMR1CS1SetTMR1CS1On#endifSetT1OSCENOnEndIfEndSubSubInitTimer2(InTMR2Pres,InTMR2Post)#ifdefPICswapfTMR2Post,FrrfTMR2Post,Wandlw120iorwfTMR2Pres,F#endif#ifdefAVR'SomewackyswappingofvariablenameshereIfTMR2Pres=ExtThenTMR2Post=AVR_EXT_TMREndIf#endifEndSubSubInitTimer3(InTMR3Source,InTMR3Pres)#ifdefPICSInitTimer3#endif#ifdefAVRIfTMR3Source=ExtThenTMR3Pres=AVR_EXT_TMREndIf#endifEndSubSubSInitTimer3T3CON=TMR3PresIfTMR3Source=ExtThenSetTMR3CSOnEndIfIfTMR3Source=ExtOscThenSetTMR3CSOnEndIfEndSubSubInitTimer4(InTMR4Source,InTMR4Pres)#ifdefAVRIfTMR4Source=ExtThenTMR4Pres=AVR_EXT_TMREndIf#endifEndSubSubInitTimer5(InTMR5Source,InTMR5Pres)#ifdefAVRIfTMR5Source=ExtThenTMR5Pres=AVR_EXT_TMREndIf#endifEndSub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
just to add on a little more support for the 16f1825 someone sent me a working eeprom routine for this chip, because the one included with gcbasic didnt work for my chip. I have tested this as working with my chip, but i dont know if it breaks support for the more standard chips.
not sure where this should go, but i couldnt use the timer on my 16f1826 enhanced pic micro. the culprit was in the timer.h file, the 16f1826 has TMR1CS0 and TMR1CS1 because of the capacitive sensors being able to be used as timer inputs (or something like that) im working on modifying the code to work with this chip and will post the updated code on here for anyone interested. this code im going to post shouldnt change function of normal chips but adds the changes needed for TMR1CS0 and TMR1CS1 (i also remembered i added TMR0CS in place of T0SE for timer0, im going to check over and test any other timers on this chip before posting the code, maybe the developer would like to put this code in the updates?
This code compiled properly but I havent tested it yet on the actual chip, but here it is anyway
I tested the code I modified with a non 16f1826 chip and the way I had the "#ifndef" in there made the compile fail. I've made the required changes and it should now work with the 16f1826, and with any other chip is used to work with. I'm a beginner at C code and really really beginner at understanding ASM codes, I just used my common sense to figure these problems out.
I'll be happy to add those changes, thanks!
just to add on a little more support for the 16f1825 someone sent me a working eeprom routine for this chip, because the one included with gcbasic didnt work for my chip. I have tested this as working with my chip, but i dont know if it breaks support for the more standard chips.