My limitations are only knowing one type of programming language 'picbasic' and I used Oshonsoft to compile them.
I can only do simple programs, and manage to make interesting little projects.
At the moment I am trying to program a 12F683 chip for a timing project. I'm used to looping 'waitms 100' and counting seconds, but there are timing errors, that need 'adjusting' to make it work.
Could anyone send me examples of counting programs showing timer interrupts please?
I've copied it for my reference, and can almost read it, but I use a higher level language, this seems to be after the language I use, 'PIC basic' has been compiled. It looks as though I might be able to back convert it? It does show me the architecture as well.
As you can see, I'm still on the baby table, and too old to get off it.
Perhaps I spoke to soon? Although the program will simulate, I hadn't noticed that it wasn't getting to the 'INTERRUPT', only going round the loop.
Here is a program that does go to 'INTERRUPT', and I think it uses TMR0 where the Eric Gibbs program uses TMR1. Is there any reason to use one or the other. This is above my skill level, and all I can do is copy and paste with a bit of data sheet checking, hoping to add the correct words in.
Would someone please run this program, to see if I can use 't' (or anything) in the 'INTERRUPT' routing to keep count. I'm using 12F683, and I will need to modify the program for 16F648A and 16F819 PICs.
Camerart.
Code:
OSCCON = %01100000 'Internal 4MHz osc
ADCON0 = 0 'A/D off
CMCON0 = 7 'Comparators off
ANSEL = 0 'Set all digital
WPU = 0 'Internal pull-ups = off
'TRISIO = %00000100
TRISIO.0 = 0 'PIN 7 as RLED
TRISIO.1 = 0 'PIN 6 as WLED
TRISIO.2 = 0 'PIN 5 as GLED
TRISIO.3 = 1 'PIN 5 as input (IN ONLY)
TRISIO.4 = 0 'PIN 4 as LED
TRISIO.5 = 0
Symbol rled = GP0
Symbol wled = GP1
Symbol gled = GP2
Symbol bled = GP4
Symbol inbutton = GP3
GPIO = %00000000 'All outputs = 0 on boot
Dim t As Word
Dim s As Byte
Dim m As Byte
Dim h As Byte
t = 0
s = 0
m = 0
h = 0
'trisb = 0xff CHECK>>>>>>>>>>>
TRISIO = 0
OPTION_REG.T0CS = 0 'OPTION_REG = %10000000 'Pull-ups = off, GPIO.2 = I/O, prescaler to Timer1
INTCON.T0IE = 1
Enable
loop:
If t >= 3965 Then '3965 for 1 second
s = s + 1
t = 0
Toggle rled
Endif
If s >= 60 Then
m = m + 1
s = 0
Toggle wled
Endif
If m >= 60 Then
h = h + 1
Toggle gled
Endif
If inbutton = 1 Then
bled = 1
Else
bled = 0
Endif
Goto loop
End
On Interrupt
Save System
t = t + 1
INTCON.T0IF = 0
Resume
I have just been thinking!!!! Are you simulating this in Oshonsoft!!!
1 second will take a very long time... it takes about 2 minutes to simulate 31mS..
For the purpose of simulation calculate it for real time.... t=256 ( every interrupt ) the trouble is the code won't be executing fast enough for you to press buttons and such...
I have just been thinking!!!! Are you simulating this in Oshonsoft!!!
1 second will take a very long time... it takes about 2 minutes to simulate 31mS..
For the purpose of simulation calculate it for real time.... t=256 ( every interrupt ) the trouble is the code won't be executing fast enough for you to press buttons and such...
I can run is fast to see what happens, and 't' doesn't add in 'WATCH VARIABLES'
Did you run the program in post #6? This uses TMR0, and also works for me. If you would now run the Eric Gibbs program after changing 'TRISB = 0x00' to TRISIO = 0x00.' for 12F683, which uses TMR1, please. this doesn't work for me.
It works in mine now, not sure why, but I keep learning stuff that might be helping.
The simulator kept stopping after 't'. I've just found out what BREAK means.
Also just found out why you changed TMR1H to only one bit left.
Thanks for your help. Keep watching, because now I need to add a little bit more to make it into a working program, that I can store in my 'MODULE' folder.
It appeared to be working,i,e, using the timing tracking option, it showed it looping through 'LOOP' and 'GOTO LOOP' as they were both flashing. I watched the TMR1 H and L registers fill up and it tripped into 'INTERRUPT' then looped in there incrementing 't' ok.
As soon as I started padding it out to be a useful program, by putting a LED turn on after 't' was 'something' in the LOOP, and did a simulation. It looped the 'loop' for a while, then once in the 'interrupt' routine, got stuck in there, adding 't's but not going to 'LOOP'.