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.

Please help with Pic problem???

Status
Not open for further replies.

johnnyquest

New Member
I have some code that appears to work fine while debugging and looking at all the registers but when I program the 16f628a it does not work.
The code displays the number 0 on one of four seven segment displays and rotates which display is on. I am driving common cathode leds directly so the led that is on is active low. I tried other programs to direct drive leds displaying the number 21 and it works fine. Please let me know what I am doing wrong.


LIST P=16f628a
ERRORLEVEL -302
include <p16f628a.inc>

TempC equ 0x20 ;temp general purpose regs

org 0
goto Start

Start
movlw 7
movwf CMCON
bsf STATUS,RP0
clrf TRISA ;make RA0-4 outputs
clrf TRISB ;make RB0-7 outputs
bcf STATUS,RP0 ;select page 0
clrf PORTA ;make all outputs low
clrf PORTB ; /
movlw b'0111' ;start with 1st display
movwf PORTA

UpdateDisplay
movf PORTA,W ;present sink value in w
movwf TempC ;save sink value in tempC
rrf TempC, F ;determine next sink value
btfsc STATUS,C ;c=1?
bsf TempC,3 ;no then reset MSD sink
movlw b'00111111'
movwf PORTB ;drive leds
movf TempC,W ;get sink value in w
movwf PORTA
goto UpdateDisplay

end
 
It is dangerous to use portA as if it were memory storage. Some pins have a different behavior from ordinary file registers. For example, portA bit 4 is open drain and so it may read differently from what was written to it.

I would use a separate file register like TempC for storage of the desired state of portA. Use that file register for RRF operation and simply write the result to portA. No need to read from portA and write to TempC.
 
The code was mainly cut from Microchip's application note AN557 and that is how they used porta under UpdateDisplay. I will change the code according to your advice and see how it works. Thanks for your input : )
 
I followed your advice and changed the code it now works fine. The app note used a 16C71 maybe it works with that chip because of the transistor setup on those pins.
Many Thanks Motion
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top