-----Original Message----- From: M. Adam Davis [SMTP:adavis@UBASICS.COM] Sent: Wednesday, 8 March 2000 7:29 To: PICLIST@MITVMA.MIT.EDU Subject: Re: Example There are only 35 instructions to learn on this PIC. The easiest way to learn how to use the PIC is to read the data sheets, and jump in. There are some books which can help you do so, and many web sites which will also help. See my links to such resources at http://www.ubasics.com/adam/pic/ I can help a little bit here with your questions: Steve Horvath wrote: > > Hello > I am fairly new to PIC programming, but have a fair bit of experience form > school involving the Intel 8031. I was wondering if someone could write a > quick program (2 minute job) to do the fallowing on a 16f84, so that I > could learn about these functions by doing them: First, the architecture is very different between these two mcus. You'll find yourself referring to the datasheet as you program. > -push W onto a stack, and pop W off of the stack There really is no direct analogy in the PIC for your stack. You have no access to the stack in the '84. If you want to program this way, then you'll need to create a software stack (which, for most things, is inefficient. It's just a different architechture, and a different way of thinking) > - input from port A to W when there is an interrupt org 4 (Save status registers if needed here (no point in saving W ;-) ) movf PORTA, W (restore status registers if needed here) RETFIE > - have a 10ms delay using the timer > - output to pb.0 through pb.4 after the interrupt > - have a 1 second timer using loops, and have the output (port B) blink on > and off every second thereafter. > > oh, and could someone tell em the difference between portA and trisA? Each i/o pin on the PIC can be an input, or an output. TRISA defines whether each pin in portA is input(1) or output(0). PORTA represents the actual status of PORTA. If you are driving all pins low, but an external circuit is driving them all high, then PORTA will read all high (ie, the real state, not the state the PIC is trying to keep it it) There are other examples out there which do all of what you are asking. Check my links above, and then start asking more specific questions. I hope this helps! -Adam A couple of explainations of the above explainations for a beginner - What is org 4 ? Program location 4 is the instruction that will be jumped to when an interrupt occurs. Normally you put a goto statement here that jumps to your interrupt handler routine. When you are finished handling the interrupt the retie statement goes to the program location stored in the stack and the program resumes from where the interrupt occurred . . . If you haven't turned interrupts off at the start of your handler and stored the state of certain registers before manipulating them you will get strange results when you turn interrupts back on and attempt to retie - beware! org 0 should have a goto statement that points to the start of your startup code. Your program code must NOT use locations 0, 1, 2, 3 or 4 as these are all reserved for special uses. It is safe to start your program from memory location 5, but I prefer to use org 6, so my programs usually have this structure - org 0 goto startup org 4 goto interrupt_handler org 6 startup bsf status,rp1 The difference between portA and trisA? Trisa is where you set up port a. It has (almost) the same address as the I/O port - it is actually on the second page of memory at 0x80 higher, but you can't add 0x80 to the port a address, you have to swap to the second page and use the same address as port a. (Don't forget to swap back!) Port a is actually 2 separate sets of circuits - 8 input circuits and 8 output circuits. If you set port a to output then output a 1 and then read the port you will not see your output, you will see what was last read in from the input circuitry. To read the current value you have to go back to the control page and swap the port to input and then read the input. Moral - try to use port pins as I or O, but don't swap them if possible. Set up everything in one go, then LEAVE THE I/O SETTING ALONE. Bye.