![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
This little bit of code I wrote as a practice while teaching myself assembly. I programmed the PIC, with options for watchdog off, and using the internal oscillator, and put in a solderless breadboard. I connected 8 LEDS with current limiting resistors on RB0-RB7. VSS is connected to ground, VDD connected to 5V, and pin 4 pulled to 5V with a 4.7k resistor.
I expected to see a "bit" to scroll across the LED's, then start again from the other side. and continue until the cows come home. What I get is a few of the LEDS in the first nibble light up in order, then nothing out of the second nibble, and nothing repeats. Is this a code error that I'm overlooking? Sorry about the formatting in the code, I guess a subquestion is, how are people attaching code so it looks nice? Thank you, Brian INCLUDE "P16F628A.inc" COUNT1 equ 20h COUNT2 equ 21h bsf STATUS,RP0 ;bank 1 clrf TRISB bcf STATUS,RP0 ;bank 0 Start CLRF PORTB movlw 01h ; load 00000001 in W movwf PORTB ; then move w to portb Loop call Delay ; delay routine rrf PORTB,1 ; rotate bits right goto Loop Delay Loop1 decfsz COUNT1,1 goto Loop1 decfsz COUNT2,1 goto Loop1 return end |
|
|
|
|
|
|
(permalink) |
|
I would suggest a shadow register for port B
Also you seem to have forgotten the carry bit on rrf, which is rotate right through carry. (Look it up in the data sheet) Your line rrf PortB, 1 needs to read Port B to work I would suggest:- ;Initialise PortBshadow equ 0x22 movlw 0x01 movwf PortBshadow ;This bit goes in the main loop instead of rrf Portb, 1 rrf PortBshadow, w ;gets bit 0 into carry bit rrf PortBshadow, f ;actual rotate and puts carry bit (was bit0) into bit7 movf PortBshadow, w movwf PortB ;put result in PortB, ignoring what was there before |
|
|
|
|
|
|
(permalink) |
|
I changed the code slightly to toggle all pins of PORTB high, then low, repeat forever...
All the leds except the one connected to RB4 are flashing. upon studying the datasheet some more, I found the following statement. "LVP configuration bit sets RB4 functionality" could this bit be the "brick wall" that stops the scrolling LEDS from entering the other nibble? I assume that LVP is Low Voltage Programming, I saw an option to enable or disable Low voltage programming in the programming software that I use (using winpic software, I'm using a PIC-PG2 from Olimex to program the PIC) another odd thing that's going on, if I touch any of the bare resistor wires or LED leads with my finger, it stops the LEDs from flashing, and they are stuck on at half brightness until I reset the power. Brian |
|
|
|
|
|
|
(permalink) | ||
|
Quote:
Quote:
Last edited by eng1; 3rd February 2008 at 09:04 PM. |
|||
|
|
|
|
|
(permalink) |
|
Ok, I disabled LVP, reprogrammed with the same code (the one that toggles the entire portB high and low) and all 8 LEDs are now happily flashing.
The issue of touching a bare wire has disappeared. Now I'll follow your example Diver300 and see about making the LED shift. From the diagram in the Datasheet, I assumed the carried bit automatically went into the other side. I will study your example and try again. Thanks for the helps, Brian |
|
|
|
|
|
|
(permalink) |
|
Thank you! The shadow register and carry fixes did the trick. Not only does the code now work..... I understand it also!
Also I learned about RB4, and disabling LVP. Many lessons learned from such a simple exercise. Brian |
|
|
|
|
|
|
(permalink) |
|
You might try checking my tutorials, the first ones do just what you've been doing.
|
|
|
|
|
|
|
(permalink) |
|
I've been looking through those tutorials since you pointed them out, alot of really good information, ty!
The rrf method for the carry is slightly different then the one described, both get the job done in this example, different methods of handling the carry bit. Your example uses few instructions, so the execution time would be faster. Diver300's example would handle multiple bits (like scrolling a group of three bits) and seeing the 2 was of doing it has taught me something also. I think my biggest problem was not disabling LVP. |
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| Question about Inchworm+ | Quan | Micro Controllers | 54 | 28th October 2007 12:20 AM |
| Please help!! program not working | vinke | Micro Controllers | 3 | 5th October 2007 04:58 AM |
| First Program in assembly, And Programmer Inchworm. | Ayne | Micro Controllers | 10 | 9th March 2007 07:26 PM |
| program for writing and testing circuits | luca-deltodesco | General Electronics Chat | 3 | 13th August 2006 10:17 AM |
| PicBasic Keypad program | Sora | Micro Controllers | 0 | 20th April 2004 07:01 PM |