Which Interrupt type to use? - Page 1
Forum section: electronics / general

author: tahmod
author_rank: Contributor
timestamp: April 20, 2013, 11:09:57 pm
content: I want to interrupt my program when the time of 5 second has passed outduring a specific area of my programandtell the program to go somewhere elsein my code.1-Is this the timer0 interupt?2-If it is timer0 interupt ,then if some one has an example so I can build it in my MPLAB?3.I have done wrote this interupt from a book, but it did not built how can I solve the errors?include p16f84a.inc;PORT A all output;Port B:bit 0 = interrupt inputorg 00goto startorg 04 ;here if interrupt occursgoto Int_Routineorg 0010;Initialisestart bsf status,rp0 ;select bank 1movlw 01movwf trisb ;portb bits 1-7 output; bit 0 is inputmovlw 00movwf trisa ;porta bits all output;Comment in or out following instruction to change;Interrupt edgebcf option_reg,intedgbcf status, rp0 ;select bank 0bsf intcon, inte ;enable external interruptbsf intcon,gie ;enable global intwait movlw 0a ;set up initial port output valuesmovwf portanopmovlw 15movwf portagoto waitorg 0080Int_Routinemovlw 00movwf portabcf intcon, intf ;clear the interrupt flagendError:1 : Found directive in column 1. (include)12 : Symbol not previously defined (status)12 : Symbol not previously defined (rp0)14 : Symbol not previously defined (trisb)17 : Symbol not previously defined (trisa)20 : Symbol not previously defined (intedg)21 : Symbol not previously defined (status)21 : Symbol not previously defined (rp0)22 : Symbol not previously defined (intcon)22 : Symbol not previously defined (inte)23 : Symbol not previously defined (intcon)23 : Symbol not previously defined (gie)26 : Symbol not previously defined (porta)29 : Symbol not previously defined (porta)35 : Symbol not previously defined (porta)36 : Symbol not previously defined (intcon)36 : Symbol not previously defined (intf)Halting build on first failure as requested.

author: Rerouter
author_rank: Super Contributor
timestamp: April 20, 2013, 11:12:35 pm
content: if you set up the timer correctly, right when you want to start measuring from, you could get the timer to overflow close to your desired 5 seconds, and use that interrupt

author: AlfBaz
author_rank: Super Contributor
timestamp: April 20, 2013, 11:33:47 pm
content: Quote from: tahmod on April 20, 2013, 11:09:57 pmNeeds to be "#include"p16f84a.inc should have all the definitions for the "symbols not defined" errors

author: mikes
author_rank: Regular Contributor
timestamp: April 20, 2013, 11:35:44 pm
content: Quote from: tahmod on April 20, 2013, 11:09:57 pmThe error tells you - don't start an include directive in the first column. Put a space in front of it. Fixing that looks like it will fix the rest of the errors - which are because the .inc wasn't loaded, and it contains the definitions.

author: tahmod
author_rank: Contributor
timestamp: April 20, 2013, 11:39:27 pm
content: -Rerouter, do you have any example of similar code ?-I wrote this code it still not working. There is all the other error left.#include p16f84a.inc;PORT A all output;Port B:bit 0 = interrupt inputorg 00goto startorg 04 ;here if interrupt occursgoto Int_Routineorg 0010;Initialisestart bsf status,rp0 ;select bank 1movlw 01movwf trisb ;portb bits 1-7 output; bit 0 is inputmovlw 00movwf trisa ;porta bits all output;Comment in or out following instruction to change;Interrupt edgebcf option_reg,intedgbcf status, rp0 ;select bank 0bsf intcon, inte ;enable external interruptbsf intcon,gie ;enable global intwait movlw 0a ;set up initial port output valuesmovwf portanopmovlw 15movwf portagoto waitorg 0080Int_Routinemovlw 00movwf portabcf intcon, intf ;clear the interrupt flagendQuote from: mikes on April 20, 2013, 11:35:44 pm

author: mariush
author_rank: Super Contributor
timestamp: April 20, 2013, 11:46:30 pm
content: How about you stop pasting code from books and come back to us when you actually bother to read the PIC datasheet and the explanation for those instructions ?It's obvious you don't read the datasheets, you don't understand the instructions, you just want to copy and paste.If you don't care about instructions, write the code in C in MPLAB and the C compiler will hide the exact instructions from you... but you still HAVE TO read at least the datasheet.

author: tahmod
author_rank: Contributor
timestamp: April 20, 2013, 11:52:54 pm
content: What is the problem? I am reading a book I just wanted to test it in the computer and it built with error. There is nothing to do with the datasheet.Quote from: mariush on April 20, 2013, 11:46:30 pm

author: c4757p
author_rank: Super Contributor
timestamp: April 21, 2013, 12:16:23 am
content: Quote from: tahmod on April 20, 2013, 11:52:54 pmThe datasheet tells you how it works! It has everything to do with the datasheet. The answer to every one of your interrupt-related questions is in there. You did say it wouldn't build, but that was only one question.

author: mariush
author_rank: Super Contributor
timestamp: April 21, 2013, 12:29:39 am
content: Quote from: tahmod on April 20, 2013, 11:52:54 pmWhat you're doing is like trying to learn a language without knowing the grammar rules and the letters. You can't just copy phrases from a book.The assembly language has particularities and the assembly language manual tells you what some assembly language specific keywords mean, how the compiler converts what you type into microcontroller code and all that.Had you read the assembly language manual, you would have learned what those error messages ": Symbol not previously defined" are telling you that the assembler has no idea what those keywords mean because you forgot to tell the assembler where you defined those keywords.Each of those keywords have some values associated with them, and those values can differ from microcontroller to another so each mcu has it's own file with those definitions, usually a .inc file.If your programming IDE or assembler software doesn't have such a file, you can MAKE one using the definitions in your microcontroller's DATASHEET, they're all there, explained.The same datasheet tells you what all those instructions do IN DETAIL, so if you'd bother to read the datasheet, you'd know why an instruction isn't executed, is skipped, whatever... how can i put it more plainly than this?The code you keep trying to run is probably relying on snippets of code from previous chapters or examples. and the book assumes you have some basic assembly knowledge and that by the time you're doing this example, you know to have a base program and just add that code to your base program, what you pasted is not a full 100% program.later edit: and the "-Is this the timer0 interupt?" is a stupid question ... timer0 isn't an interrupt... it's a stupid timer, your mcu may have one or more timers and it's up to you how to enable them and configure to optionally do an interrupt when time expires. The DATASHEET has a whole chapter about timers WITH examples, read the f**king datasheets and understand the code, don't just paste from books.

author: Skimask
author_rank: Super Contributor
timestamp: April 21, 2013, 12:34:15 am
content: Ya...I give up too.Apparently the word "datasheet" is not in the vocabulary.

author: mariush
author_rank: Super Contributor
timestamp: April 21, 2013, 12:51:44 am
content: Here's what you need to understand, if you don't read these we can't help you here:MPASM_&_MPLINK_User_Guide :http://savedonthe.net/download/482/MPASM_-_MPLINK_User_Guide_33014k.htmlThe first 4 chapters explain how Assembler language words, what the keywords mean, how to write assembler programs. From the 5th chapter you already have examples of programs explained line by line. But you can't just jump to a random example and paste it and think it would work.Read the manual, it's important.Pickit3 Lessons:http://savedonthe.net/download/483/PICkit_3_Lessons_UG_41370c.htmlLessons source code:http://savedonthe.net/download/484/PICkit-3-Debug-Express-Lessons.htmlThis is a PDF with source code explained, but it's for PIC18 chips that come with the Pickit3 programmer (if you get it with the development board). PIC18 chips are similar to PIC16 chips, so if you COMPARE the datasheets of your PIC16 chip with the datasheet of the PIC18 chip presented in those lessons, you can adjust the source code to work.The lessons are in C , which is much, much easier to understand.Without reading at least the Assembler manual and the datasheet for your own PIC chip, you have little chance of understanding how the programs you keep copying from books. Do yourself a favor and read them.

author: Skimask
author_rank: Super Contributor
timestamp: April 21, 2013, 04:22:33 am
content: Maybe the homework is due next week?

author: tahmod
author_rank: Contributor
timestamp: April 21, 2013, 09:03:11 am
content: -Thanks mariush I am planning to read the Pickit3 Lessons, Lessons source code and the MPASM guide. The Pickit 3 has some good example of project.-I look at the datasheet for the "Symbol not previously defined", you need to define it with equ but when I assemble it give me "Argument out of range. Least significant bits used.".I define all the key wordsstatus equ 03porta equ 05trisa equ 05portb equ 06trisb equ 06trisd equ 08latd equ 11intcon equ 0brp0 equ 16option_reg equ 17intedg equ 18rp0 equ 19inte equ 20gie equ 21intf equ 22loop1 equ 12loop2 equ 13loop3 equ 14tisr equ 15Quote from: mariush on April 21, 2013, 12:51:44 am

author: mariush
author_rank: Super Contributor
timestamp: April 21, 2013, 12:04:14 pm
content: QuoteDO THATfirst. Don't expect to get answers before you do that, because even if we give them to you, you won't understand why you have to do it like we say. The MPASM guide tells you that.You can keep asking questions and wasting days of your time and not remaining with anything in your head after getting answers, or you can start reading and trying to understand for a few hours and find your own answers. There's no magic solution.If you find the Pickit3 lessons more accessible, just drop the assembler language altogether and start doing C. The C compiler comes with headers for various PIC chips, just like the asm compiler should come with include files for chips.But for C, the pic chip datasheet is like a manual, it explains everything you need to know. You need the datasheet anyway for the definitions for assembler.