![]() | ![]() | ![]() |
| | #61 |
|
wow ive spent all day on this how hard can it be to make this work here is my code. I want it to read the 8 bit string and then one digit after the other send it out on pin GP0 and then after each digit it needs to clock on GP1 the one im using needs a low to high to clock it please help ive been at this for days I don't know if the engine works or not ether please haha I only want the first 4 LED's to light up on the shift hence the '11110000'Code: list p=12F509 ; list directive to define processor
#include <p12F509.inc> ; processor specific variable definitions
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
cblock 0x07
;***** VARIABLE DEFINITIONS
count,temp
D
CP
delay
endc
;**********************************************************************
RESET_VECTOR CODE 0x3FF ; processor reset vector
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value
start
movlw b'11110000'
movlw temp
call shift
goto start
;********Subroutines********
shift
shift5 movlw 0x08 ;set loop counter
movwf count
movf INDF,w ;get a byte
movwf temp
shift1 rrf temp,f ;rotate ms-bit into carry
btfsc STATUS,C ;is it 0?
goto shift2 ;no, shift out a 1
goto shift3 ;yes, shift out a 0
shift2 bsf GPIO,1
nop
bsf GPIO,1 ;blip clock
nop
bcf GPIO,1
goto shift4
shift3 bcf GPIO,1
nop
bsf GPIO,1 ;blip clock
nop
bcf GPIO,1
shift4 decfsz count,f ;done 8-bits?
goto shift1 ;no, go again
retlw 0
END ; End of program !!
Last edited by Darkstar64; 3rd October 2008 at 10:45 PM. | |
| |
| | #62 | |
| Quote:
1. You haven't set your pins to outputs with TRIS. By default, PIC pins are inputs on reset. To make them outputs you must set them yourself. 2. You're using the same pin for both data and clock. That won't work. Here's your code neatened up and decluttered (so I could read it comfortably). I did not make the fixes listed above. You can do that. You don't need to mess around with that reset vector thing or the osc calibration value. I removed that stuff. Code: #include <P12F509.inc> __CONFIG _MCLRE_ON & _WDT_OFF & _IntRC_OSC cblock 0x07 count,temp endc org 0x000 main movlw b'11110000' movlw temp call shift5 goto main shift5 movlw 0x08 ;set loop counter movwf count movf INDF,w ;get a byte movwf temp shift1 rrf temp,f ;rotate ms-bit into carry btfsc STATUS,C ;is it 0? goto shift2 ;no, shift out a 1 goto shift3 ;yes, shift out a 0 shift2 bsf GPIO,1 nop bsf GPIO,1 ;blip clock nop bcf GPIO,1 goto shift4 shift3 bcf GPIO,1 nop bsf GPIO,1 ;blip clock nop bcf GPIO,1 shift4 decfsz count,f ;done 8-bits? goto shift1 ;no, go again retlw 0 end
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 4th October 2008 at 01:03 AM. | ||
| |
| | #63 |
|
ok so it would look something like this then o and about the tris I had that done in another part I deleted just forgot to put it back in I guess . I changed the pins is this correct and I added the tris part its just not shown is that everything? Code: #include <P12F509.inc> __CONFIG _MCLRE_ON & _WDT_OFF & _IntRC_OSC cblock 0x07 count,temp endc org 0x000 main movlw b'11110000' movlw temp call shift5 goto main shift5 movlw 0x08 ;set loop counter movwf count movf INDF,w ;get a byte movwf temp shift1 rrf temp,f ;rotate ms-bit into carry btfsc STATUS,C ;is it 0? goto shift2 ;no, shift out a 1 goto shift3 ;yes, shift out a 0 shift2 bsf GPIO,1 nop bsf GPIO,2 ;blip clock nop bcf GPIO,2 goto shift4 shift3 bcf GPIO,1 nop bsf GPIO,2 ;blip clock nop bcf GPIO,2 shift4 decfsz count,f ;done 8-bits? goto shift1 ;no, go again retlw 0 end Last edited by Darkstar64; 4th October 2008 at 05:30 AM. | |
| |
| | #64 | |
| Quote:
Code: movlw b'11001000' ;clear T0CS for output on GPIO2 option movlw b'00001000' ;set pins to all outs tris GPIO Code: bcf OPTION,T0CS
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 4th October 2008 at 05:56 AM. | ||
| |
| | #65 |
|
Cube page on my site (link below) has been updated. There's a YouTube video of it working too.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | |
| |
| | #66 |
|
Ok well thanks alot all give that a try now when I write this code it should only lite up the first 4 LED's right and they will stay on just making sure bc its been doing some weird stuff with some of code ive givin it thanks alot for the help all let you know how it goes
| |
| |
| | #67 |
|
Ok it just doesn't want to work no matter what I try I am hooking up the Data and Shift right into the PIC on pins GP1 and GP2 can you post a schmatic I could try with my MC74HC595A shift register and some assembler just to test to make sure its working I have tried everything I can shift it manually but when I hook it into the pic nothing happens or something happens just not what I told it to do here is the code I have programmed in it would help if you could give me a small simple test schmatic that I could use I have one but its for manually shifting the register. I don't think ive ever had so much problems with one thing it just won't work I don't get it
Last edited by Darkstar64; 4th October 2008 at 08:53 PM. | |
| |
| | #68 |
|
I don't have time to study your code in detail, but are you latching your output?
| |
| |
| | #69 | |
| Quote:
![]() My schematic wouldn't help you much. I'm using totally different parts. Show me your schematic and your code! Then I (and/or others) can probably spot the problem. A photo is sometimes helpful too. Camera set on macro with a steady hand and LOTS of light. I could maybe even breadboard up the identical thing for better troubleshooting.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #70 |
|
No im not but its doing it by itself for some unknown reason I don't even have a connection hooked up to it so all try addding a wire to GP4 to latch it it says a low to high will latch it so all test it out fast and tell you what happens ok so my final code is here with the latch at the very bottom is this correct ? and when I post the code into here it comes out weird its not like that in MPLAB Code: #include <P12F509.inc> __CONFIG _MCLRE_ON & _WDT_OFF & _IntRC_OSC cblock 0x07 count,temp endc org 0x000 main movlw b'11001000' ;clear T0CS for output on GPIO2 option movlw b'00001000' ;set pins to all outs tris GPIO movlw b'11110000' movlw temp call shift5 goto main shift5 movlw 0x08 ;set loop counter movwf count movf INDF,w ;get a byte movwf temp shift1 rrf temp,f ;rotate ms-bit into carry btfsc STATUS,C ;is it 0? goto shift2 ;no, shift out a 1 goto shift3 ;yes, shift out a 0 shift2 bsf GPIO,1 nop bsf GPIO,2 ;blip clock nop bcf GPIO,2 goto shift4 shift3 bcf GPIO,1 nop bsf GPIO,2 ;blip clock nop bcf GPIO,2 shift4 decfsz count,f ;done 8-bits? goto shift1 ;no, go again bcf GPIO,4 bsf GPIO,4 retlw 0 end Last edited by Darkstar64; 4th October 2008 at 09:03 PM. | |
| |
| | #71 | |
| Quote:
Darkstar, the reason my code has no latching is because the shift register I use auto-latches. The leading 1 is pushed into the latch by the 36th bit shifted. A 74HC595 must be manually latched.
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #72 | |
| Quote:
Put a NOP between those two, or you may have a problem. Code: bcf GPIO,4 bsf GPIO,4 retlw 0 end
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | #73 |
|
Ya at the bottom of my code is the latching now just before retlw 0 but it still doesn't want to work haha
| |
| |
| | #74 |
|
Ok it seems to be working but the LED's are wrong for some reason here is what it is happening '10011000' instead of the '11110000'
| |
| |
| | #75 |
|
Back to basics. Why not put a 1 on the output pin, clock it, latch it, and test whether the first output pin on the shift register is high. edit: Disregard. I see it's working. Last edited by skyhawk; 4th October 2008 at 09:12 PM. | |
| |
|
| Tags |
| pic, registers, shift, working |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| 16 bit serial in parallel out shift registers | forder | Electronic Projects Design/Ideas/Reviews | 14 | 2nd March 2009 09:17 AM |
| Cascading Shift Registers Help | Suraj143 | Electronic Projects Design/Ideas/Reviews | 13 | 5th June 2008 08:33 AM |
| Load shift-registers via SPI? | Mike, K8LH | Micro Controllers | 14 | 14th February 2008 03:00 AM |
| Help loading shift registers... | jrz126 | Micro Controllers | 0 | 14th November 2005 01:13 PM |
| shift registers | jrz126 | Electronic Projects Design/Ideas/Reviews | 8 | 25th September 2004 02:35 AM |