Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC understanding

Status
Not open for further replies.
I have been trying to program my PIC18F242 for a while now and I am stuck on a few important details. I am using ASM to program my PIC but if you can help me understatnd what is going on it would be greatly appreciated.

First; I have to interface a keypad with my PIC, I have read Nigels tutorial and it was a big help. I plan on using a HEX key pad but it instead of having it labeled A-F it will be control commands such as MENU, ENTER and what not. I am very confused on how to get the main code to alter it's program path based on the value returned. The best thing I can think of right now is to have the code run something like:
Code:
cpfsgt   MENU   ;this would be the value for the menu command
goto     $+2
cpfslt    MENU
goto     $+2
;command for adjusting the menu pointer

Is there a better way to do this?

I do have some more issues but I feel like I am making progress with them so I will post them here when I feel I can't make any more progress.
 
Your keypad routine should return just a number - say 0 to 15 - you can then use that in a jump table, with each one jumping to the relevent routine for that key.
 
Hi,

As per Nigels comments, but just regarding your compare code, you don't need to compare twice, greater and then less , just use the equals CPFSEQ.

Also you might find it better to use labels in the Goto instead of $+2 etc as its so easy to mix things up if you start borrowing 16F code examples.
 
So how would I create a jump table in ASM?

If it helps, here is how I am hoping to have the program run:
1) Start up- set configureation bits, clear all outputs, establish inputs and outputs
2) send a "Hello" message to the LCD
3) send a "Mode:" message to the LCD
4) check keypad for mode number- branch to specified mode number
5) send a "Rate:" message to the LCD
6) check keypad for rate number- store as an interupt counter for timer 0
7) send a "Output:" message to the LCD (followed by a series of X's to indicate which LEDs are on)
8) execute a NOP until an interupt occurs
9) on a key pad interupt, get the new key value (timer 0 is a high priority interupt, while key pad is a low priority)
10) on a timer 0 interupt, change the state of the LEDs based on the specified mode (if the interupt counter is 0 then it changes state and resets the interupt counter, if it's not 0 then it decrements it once and returns)
11) return from last interupt and continue
12) loop forever

What I am most concerned about is if the timer0 interupt occurs, it will still have to look which mode to branch to in the table since I can't have a different high priority interupt before each mode routine.
 
What I am most concerned about is if the timer0 interupt occurs, it will still have to look which mode to branch to in the table since I can't have a different high priority interupt before each mode routine.

Hi,

All you need to do, is when the program enters the ISR it tests for which Interrupt bit has been set on, Timer0 IF or keypad RB IF and then goes to the appropriate routine.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top