PDA

View Full Version : Program works!, however dont understand some DT-INT stuff.



wdmagic
- 20th April 2013, 23:46
Using a 18F4550 with internal default OSC. I started by using Darrel's INTs using the blinking LED program (http://www.darreltaylor.com/DT_INTS-14/blinky.html)that worked, changing
T1CON = $31 was about 2 seconds between blinks so I tried
$01 that set it to about 2hz
$11 set it to about 1hz
$00 did nothing nor did $31, $10, $20

now on his Timer template page (http://www.darreltaylor.com/DT_INTS-14/TimerTemplate.html)he has T1CON's listed as whole numbers 00, 10, 20, 30. I tryed these and program compiled but didnt run. This could be from me not specifying frequency, prescaler etc.. Im happy with the results so far, and right now I am just going to be using either 1 timer or 1 INT and 1 timer. I currently dont have to set it to run at a particular frequency so Im not studying that timer template page so much as the led blinky page and the Hello world page (http://www.darreltaylor.com/DT_INTS-14/hello.html). I would like to know where to find a listing where the $31 came from? is there a chart or a rule for generating this number?

Ive created a new file to test my EEPROM animations and it works great, what it does is store 64 Custom characters (8 Characters x 8 Frames) and it load them to CGRAM on the LCD and animate them, it allows for 8 Animated characters on the screen at the same time! What I am going to post is the primer on this, anyone should be able to expand it however they want, i will only be using a Single animated character with 7 frames to keep it simple.

This Program will place a animated battery being charged whereever you want to place the 0 Character in CGRAM "LCDOUT 0"


Include "LCD_D.bas" ' Defines for LCD using PORTD
INCLUDE "ADC_Default.bas" ' Defines for the ADC System
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
EEPROM 0,[14,17,17,17,17,17,17,31] ' Cust Char #0
EEPROM 8,[14,17,17,17,17,17,31,31] ' Cust Char #1
EEPROM 16,[14,17,17,17,17,31,31,31] ' Cust Char #2
EEPROM 24,[14,17,17,17,31,31,31,31] ' Cust Char #3
EEPROM 32,[14,17,17,31,31,31,31,31] ' Cust Char #4
EEPROM 40,[14,17,31,31,31,31,31,31] ' Cust Char #5
EEPROM 48,[14,31,31,31,31,31,31,31] ' Cust Char #6
CGLOAD VAR WORD : CGLOAD = 0 ' Variable for holding Character # to Load
CGLLOC VAR BYTE : CGLLOC = 0 ' LCD Location to Store Character (0 to 7)
CGLOOP VAR BYTE ' Variable for Selecting Data Bits
CGDATA VAR BYTE ' Variable to Hold Character Data
Position Var WORD : Position = 0' Animation Frame
LCDOUT $FE, 2
Pause 1000
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler TMR1_INT, _Animation1, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
T1CON = $11 ; 01=.5s, 11=1s
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
Main:
LCDOUT 0
PAUSE 500
GOTO Main
'---[TMR1 - interrupt handler]--------------------------------------------------
Animation1:
CGLOAD = Position * 8 ' Converts your Character Selection to EEPROM Address
CGLLOC = 64 ' Converts LCD Slot to LCD Memory Address
LCDOUT $FE, CGLLOC
FOR CGLOOP = CGLOAD to (CGLOAD + 7) 'Sets 1st Memory Address to Read + Next 7
read CGLOOP, CGDATA ' Retrieve byte from EEPROM
LCDOUT CGDATA
next CGLOOP
position = position + 1
if position > 6 then position = 0
@ INT_RETURN


With some basic modifications you should be able to add up to 8 animated characters that are animated even if not being displayed onscreen. this is just an example program to simulate a battery charging icon on a LCD. feel free to let me know if you see something that can be shortened and if you can solve any of my questions at the top.

HenrikOlsson
- 21st April 2013, 00:22
Hi Chris,

I would like to know where to find a listing where the $31 came from? is there a chart or a rule for generating this number?
That would be in the datsheet for the particullar PIC...

On the 18F4550 (and I suspect most other PICs) setting T1CON to $31 means it's setup to run TMR1 with a prescaler of 1:8. Since you don't have a DEFINE OSC xx in your code I'm assuming it's 4MHz which means an instruction cycle of 1us. Since you're letting the timer free run (you don't reload it in the interrupt service routine) it'll overflow and trip an interrupt every 2^16*8*1us=0.524288 seconds or around 2Hz.

The reason the program compiled but "didn't run" is because setting T1CON to $00, $10, $20 or $30 does set the prescaler but it does NOT actually turn the timer ON. If the timer isn't turned ON it won't run and no interrupts will get tripped. Please note that in Darrels examples he has a special subroutine which he GOSUBs to actually start the timer - you don't - so if you don't set bit 0 of T1CON the timer won't run and interrupts won't fire.

/Henrik.

wdmagic
- 21st April 2013, 00:40
Thanks for the quick reply henrik, I understand I didnt turn on the timer, when I started, I just copied darrels blinky program and it worked, changing the 31 to 30 made it not work, is it because that 1 ends up being the bit that turns timer on? so...

if i want to use the whole numbers I would set it up like this?



T1CON = $30
T1CON.0 = 1

wdmagic
- 21st April 2013, 04:26
OK Got a problem, took and went back to basics and just want a timer to flash a LED and a button on RB0 (int)

heres my code, the INTCON and OPTION are remarked out because I copied them in from other notes on web, not sure if they were correct and they threw sytax errors


INCLUDE "DT_INTS-14.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR1_INT, _ToggleLED2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts
'INTCON = %10011000 <--not sure if this was needed or incorrect (it was not in the blinky or the hello word program)
'OPTION_REG = %01000000 <-- same as above, shows up as syntax error (Both lines copied from other peoples code)
'without these 2 lines I get INTCON, INTF not found

T1CON = $11 ; 01=.5s, 11=1s

Main:
PAUSE 500
GOTO Main

'---[INT - interrupt handler]---------------------------------------------------
ToggleLED1:
Toggle PORTB.1
@ INT_RETURN

'---[TMR0 - interrupt handler]-------------------------------(Animation)------
ToggleLED2:
Toggle PORTB.2
@ INT_RETURN

wdmagic
- 21st April 2013, 05:03
Sorry changed the top 2 lines to


INCLUDE "DT_INTS-18.bas" ; Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ; Include if using PBP interrupts

'I also changed INT_INT to INT0_INT



throws error

Error 101 INT_ENABLE Priority state not found

does this no matter the INT0 change

HenrikOlsson
- 21st April 2013, 07:52
Hi Chris,
First, regarding the timer. You are correct on all accounts. Changing from $31 to $30 does strip of setting the least significant bit which results in the timer being left in its off state. You can set the bit indivudually if you want.

Second, in your latest code snippet you're declaring an interrupt for TMR1 (TMR1_INT) but you're then trying to enable the interrupt for TMR0 - which at that point doesn't have an interrupt service routine assigned to it.

ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT_INT, _ToggleLED1, PBP, yes
INT_Handler TMR1_INT, _ToggleLED2, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM

@ INT_ENABLE INT_INT ; enable external (INT) interrupts
@ INT_ENABLE TMR0_INT ; enable Timer 0 interrupts <- Here you're enabling TMR0_INT which isn't properly declared.

/Henrik.

wdmagic
- 21st April 2013, 23:11
thanks for catching that, I also had found that dt14 doesnt work when compiling to a 18 chip... I copied all the code to a new page and started going thru it line by line, I found that error but it still didnt run. I fixed it by copying the lines


@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
T1CON = $11 ; 01=.5s, 11=1s
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

strait from the webpages back to my program and it worked. I went back to my original file and pasted them and they were identical lines


@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
T1CON = $11 ; 01=.5s, 11=1s
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
T1CON = $11 ; 01=.5s, 11=1s
@ INT_ENABLE TMR1_INT ; enable Timer 1 interrupts

All I had done was add some spaces to line stuff up a bit. and removed old lines, with the added spaces and it worked, So I was wondering if you have to have spaces just right, so I added the spaces back to the new code and it still worked??? so now I'm confused, then I went back to my first interupt program and modified that the same as these and it generated that error, thats when I noticed all the ones failing were useing DT_INTS-14.bas at the top. which worked for me as long as I only did either a timer or a INT, but not both, swapping over to the 18 and fixing that timer 0/1 error seems to have fixed it.

I was getting frustrated that I was overlooking my error of copy/pasting from multiple sources, darrels timer program used timer 1, and the others used timer0 so there was a mixup during copy/paste.

I have bot his sets of files for DT_INTS-14.bas and DT_INTS-18.bas If I assume the 18 is for 18F series chips whats 14 for, or am I not correct? he has 2 websites almost identical but I got confused on that. Right now the only chips I am using is the 18F4550, 12F683 & 675. I have others but am trying to stick mainly to these.

But its working now and Ive seen the errors, Frustration Over! at least for that lesson :) now today im going to try to learn to add a keypad to INT if I can.
Thanks for your help.

Demon
- 22nd April 2013, 01:53
Spaces were an issue in assembler when I went to school.

Robert

HenrikOlsson
- 22nd April 2013, 06:09
Hi,
Yes, DT_Ints-14 is for PIC12 and PIC16 parts (which has a 14bit core) while DT_Ints-18 is for PIC18 devices.

/Henrik.

Darrel Taylor
- 22nd April 2013, 06:13
If you are using an 18F part ... you must use DT_INTS-18.

The other PIC's ... 12F, 16F and 16F1, are all 14-bit cores.
For those you must use DT_INTS-14