My isr is long, but at 4MHz and no delay instructions it has not to be the problem.
Well, I tried to set the presale to 1:16. 1:4 had to make a interrupt every 2mSec.
after that I tried to turn off the timer and after that, turn it back on. All had no effect.
So, I came back here.
This is all my code:
first config, var's and isr
then main loop
after that the complete menu
Much of the code was for a rtc-clock using a lcd. Thats why some of the loops are empty now.
Code:@ device pic16F628a, INTRC_OSC_NOCLKOUT @ device pic16F628a, MCLR_ON @ device pic16F628a, LVP_OFF @ device pic16F628a, WDT_OFF @ device pic16F628a, PWRT_ON @ device pic16F628a, BOD_OFF'ON INCLUDE "modedefs.bas" 'for shiftout pause 50 ' Defines ' ---------------- 'I2C pins DS_SCL VAR PORTA.0 ' I2C clock pin DS_SDA VAR PORTA.1 ' I2C data pin 'RTC CON %11010000 ' RTC device address (byte addressing) not needed 'Setting the RTC so we can get out 1Hz tick output '------------------------------------------------- ' -------------- RTC definitions ----------------- SecReg CON $00 ' seconds address (00 - 59) ' MSB of SecReg must be set to a 0 to enable RTC MinReg CON $01 ' minutes address (00 - 59) HourReg CON $02 ' hours address (01 - 12) or (00 - 23) DayReg CON $03 ' day address (1 - 7) DateReg CON $04 ' date address (01 - 28/29, 30, 31) MonthReg CON $05 ' month address (01 - 12) YearReg CON $06 ' year address (00 - 99) ContReg CON $07 ' control register RTCflag CON 0 ' RTC flag (location 0 of internal EEPROM) cntrl CON %00010000 ' sets the SQW/OUT to 1Hz pulse, logic level low ' The variable below holds the values entered: 'menu var's _sec VAR BYTE ' $00 set seconds _min VAR BYTE ' $56 set minutes _hr VAR BYTE ' $23 set hour _day VAR BYTE ' $06 set day _date VAR BYTE ' $28 set date _mon VAR BYTE ' $02 set month _yr VAR BYTE ' $03 set year 'rtc var's sec VAR BYTE ' seconds MINs VAR BYTE ' minutes hr VAR BYTE ' hours day VAR BYTE ' day date VAR BYTE ' date mon VAR BYTE ' month yr VAR BYTE ' year 'button input '------------------- SetButton var PORTa.7 ' Press to Set/memorise Button DecButton var PORTa.3 ' Press to Decrement Button IncButton var PORTa.2 ' Press to Increment Button 'other var's '------------------ CounterA var byte ' General purpose Variable CounterB var byte ' General purpose Variable CounterC var byte ' General purpose Variable CounterD var byte ' General purpose Variable ButtonRepeat con 200 ' Timeperiod (in mS for Edit Buttons auto-repeat ' should you want to hold them down... RTCCtrl var byte ' Control TimeOut var word ' Variable for SetUp Menu Time-Out SetTime var byte ' 12/24 Hour Clock RTCWDay var byte ' Weekday timeformat var word ' place for displaying am/pm counter var byte counter2 var byte counter3 var word ' delaycounter counter4 var word ' counter at redisplayloop segments var byte myBCD var byte toDEC var byte 'I/O pins 'port conditions '--------------- CMCON=7 TRISA=0 TRISB=0 PORTA=0 PORTB=0 'timer and interruptconditions '---------------- PIE1 = %00000010 '0------- Disable EE write complete interrupt '-0------ Disable comparator interrupt '--0----- Disable USART receive interrupt '---0---- Disable USART transmit interrupt '----x--- unimplemented '-----0-- Disable CCP1 interrupt '------1- Enable TMR2 to PR2 match interrupt '-------0 Disable TMR1 overflow interrupt T2CON = %00000010 'X------- Unimplemented '-0000--- postscale 1:1 '-----0-- Timer2 off '------10 prescaler 1:16 GIE VAR INTCON.7 PEIE VAR INTCON.6 TMR2IF VAR PIR1.1 TMR2ON VAR T2CON.2 RELOAD CON 131 ON INTERRUPT GOTO ISR TMR2 = RELOAD PR2 = 0 ' load period register for 2mSec PEIE = 1 ' Enable peripheral interupt GIE = 1 ' enable Global interrupt TMR2ON = 1 ' TMR2 ON GOTO LOOP disable ISR: 'interruptroutine TMR2ON=0 'later to use to reduce the isr text. then only shiftout the var's if counter3=>200 then 'number of shiftouts counter3=0 else counter3=counter3+1 endif 'hours 'the one that is 0 wil blink 'for segments the opposite counter = %01111111 '1 segment toDEC = hr if hr.6=1 then '12 uurs mode todec = todec <<3 todec = todec >>7 else '24 uurs mode todec = todec <<2 todec = todec >>6 endif gosub findsegments if hr.6 = 1 then 'add in the am/pm indication if hr.5 = 1 then segments.7 = %1 endif endif gosub segmentsshiftout counter = %10111111 '2 segment toDEC = hr toDEC = toDEC << 4 'shiftout unusable data todec = todec >> 4 'shiftback usable data gosub findsegments if portA.6 = 1 then segments.7 = %1 'add the blinkin dot gosub segmentsshiftout 'minits counter = %11011111 '3 segment toDEC = MINs todec = todec >> 4 'shiftback usable gosub findsegments gosub segmentsshiftout counter = %11101111 '4 segment toDEC = MINs todec = todec << 4 'shiftout unusable data todec = todec >> 4 gosub findsegments gosub segmentsshiftout 'seconds counter = %11110111 '5 segment toDEC = sec todec = todec >> 4 'shiftback usable gosub findsegments gosub segmentsshiftout counter = %11111011 '6 segment toDEC = sec todec = todec << 4 'shiftout unusable data todec = todec >> 4 gosub findsegments if hr.6=1 then 'mode indication segments.7=%1 endif gosub segmentsshiftout counter = %11111111 'to take care that no segment is blinking harder todec = %00000000'todec >> 4 gosub segmentsshiftout segmentsshiftout: SHIFTOUT PORTB.0, PORTB.1, LSBFIRST,[counter\8,segments\8] 'data, clock pulsout PORTA.4,1 return findsegments: if todec=%00000000 then '0 segments = %01111110 endif if todec=%00000001 then '1 segments = %00110000 endif if todec=%00000010 then '2 segments = %01101101 endif if todec=%00000011 then '3 segments = %01111001 endif if todec=%00000100 then '4 segments = %00110011 endif if todec=%00000101 then '5 segments = %01011011 endif if todec=%00000110 then '6 segments = %01011111 endif if todec=%00000111 then '7 segments = %01110000 endif if todec=%00001000 then '8 segments = %01111111 endif if todec=%00001001 then '9 segments = %01111011 endif return TMR2 = RELOAD TMR2ON = 1 TMR2if=0 ' Clear interrupt flag resume enable LOOP: I2CRead DS_SDA,DS_SCL,$D0,$00, [sec,MINs,hr,day,date,mon,yr] ' Read Ds1307 If sec.7=1 then goto coldstart If setbutton = 0 then 'if setbutton is pressed _hr=hr _min=MINs _sec=sec gosub SetButtonRelease Gosub SetTimeAndDate 'after release endif counter3=0 repeat 'show the segments for 5 times. pauseus 10 until counter3 > 5 GoTo Loop end Segmentswrite2:'write settimevar's to timevar's in bcd CounterA=_hr If SetTime=1 then If CounterA>12 then CounterA=CounterA-12 If CounterA=0 then CounterA=12 endif Gosub ConvertBCD hr=CounterB ' Save the Hours Value If SetTime=1 then hr.6=1 ' Save the 12 Hour Mode Flag If _hr=>12 then hr.5=1 ' Save the 'PM' Flag endif ' ' Save Minutes ' ------------ CounterA=_min Gosub ConvertBCD MINs=CounterB ' ' Save Seconds ' ------------ CounterA=_sec Gosub ConvertBCD sec=CounterB 'gosub segmentswrite return 'paste here the other half of the code




Bookmarks