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.

PIC16F628 code error

Status
Not open for further replies.

kalingajay

New Member
Hi all,

I have few numbers of PIC16F628 (not 16F628A) microcontrollers. I wrote a .asm code to test PICs like below.


;****************************************************************
LIST P=16F628
#include <P16F628.INC>
__CONFIG _PWRTE_ON & _WDT_OFF & _ER_OSC_NOCLKOUT & _BODEN_OFF & _LVP_OFF & _CP_OFF & _MCLRE_OFF
errorlevel -302

;****************************************************************
org 0x00
goto init
org 0x04
;****************************************************************
init

clrf PORTA
clrf PORTB
movlw 0x07 ; Turn comparators OFF and enable pins for I/O
movwf CMCON
bcf STATUS,RP1
bsf STATUS,RP0 ;switch to bank 1
clrf TRISA
clrf TRISB
bcf STATUS,RP0 ;switch back to bank 0
;****************************************************************

START MOVLW B'00000001' ;
MOVWF PORTB
CALL DELAY
MOVLW B'00000010' ;
MOVWF PORTB
CALL DELAY
MOVLW B'00000100' ;
MOVWF PORTB
CALL DELAY
MOVLW B'00001000' ;
MOVWF PORTB
CALL DELAY
MOVLW B'00010000' ;
MOVWF PORTB
CALL DELAY
MOVLW B'00100000' ;
MOVWF PORTB
CALL DELAY
MOVLW B'01000000' ;
MOVWF PORTB
CALL DELAY
MOVLW B'10000000' ;
MOVWF PORTB
CALL DELAY
GOTO START

;****************************************************************

DELAY MOVLW .75
MOVWF 2CH
STK DECFSZ 2AH,1
GOTO STK
DECFSZ 2CH,1
GOTO STK
RETURN

END


The code can compile and program PIC without any error. But with practical circuit any LED not light up. Please anyone can tell me what is the error of this code?
 
It is probably your config, you have it set to use an external resistor, try setting it to use the internal oscillator.

Mike.
 
It is probably your config, you have it set to use an external resistor, try setting it to use the internal oscillator.

Mike.
Thank you for your reply. But I tried both ways. Last time I used a PCB with external RC oscillator. I send you schematic.

Kalinga.
 

Attachments

  • 16F628-circuit.jpg
    16F628-circuit.jpg
    22.3 KB · Views: 341
Jon said:
I posted it to Paste Bin since the code tags on ETO no longer maintain the proper spacing between columns in asm code.

Are you sure!! If you do it manually it seems to be okay

Code:
;****************************************************************
   list     p=16F628, r=dec, w=-302
   include     <P16F628.INC>
   __config   _LVP_OFF & _BOREN_OFF & _PWRTE_ON & _WDT_OFF & _FOSC_INTOSCIO
 
;****************************************************************
 
   cblock   0x70
     COUNT1
     COUNT2
     COUNT3
   endc
 
 
;****************************************************************
   org   0x00
   goto   init
 
   org   0x0100
;****************************************************************
init
 
   clrf   PORTA     ;clear PORTA output latch
   clrf   PORTB     ;clear PORTB output latch
   movlw   0x07     ;Turn comparators OFF and enable pins for I/O
   movwf   CMCON 
   banksel   TRISA     ;bank 1
   clrf   TRISA 
   clrf   TRISB
   banksel   PORTA      ;bank 0
;****************************************************************
 
   bsf   STATUS,C   ;set carry bit
   rlf   PORTB,F     ;shift left
   movlw   4      ;786mS delay
   call   DelayVar
   goto   $-3     ;loop forever
 
;****************************************************************
 
DelayMain 
   movlw   256
   movwf   COUNT1
   movwf   COUNT2
   decfsz   COUNT1,F
   goto   $-1
   decfsz   COUNT2,F
   goto   $-3
   return
 
DelayVar
   movwf   COUNT3
   call   DELAY
   decfsz   COUNT3,F
   goto   $-2
   return
 
   end

Oh!! You mean the second column... I see!!
 
The ER oscillator only uses a resistor and not a capacitor, however, 5pf is not going to make much difference. What I did notice was the lack of capacitors on the 7805. I can't see any reason the above code won't work so check your circuit carefully.

JON, rlf will leave the code open to RMW errors if any pin is heavily loaded (LED without resistor etc.). Also, relying on the Carry bit not getting corrupted is not a good idea, especially when the OP tries modifying the code which he no doubt will. Not criticizing, just pointing it out for any future readers.

Mike.
 
Try a '628a version.
I've had all kinds of compatibility issues with the '628, you programmer may not be programming correctly, does the device verify?
 
Mike said:
rlf will leave the code open to RMW errors
I doubt you wold get RMW errors with a basic resistor / LED circuit... I thought it was more on the slow changing circuits, capacitance and the like....
 
I doubt you wold get RMW errors with a basic resistor / LED circuit... I thought it was more on the slow changing circuits, capacitance and the like....
If you had quoted a bit more it would have said "LED without resistor" as I was warning any future readers about the possible problem, in fact I said that as well.

Mike.
 
That is something that is unlike the 8051. With the 8051 and RMW instructions, it is the port latch that is read, then modified, then re-written. I wasn't aware that the PIC reads the pin instead of the latch. My apologies.

That being said, there should NEVER be a time where the pins are driving LED's without resistors. Even when multiplexing a 7-segment display, I've always used at least 100R resistors on the cathode drive port. Then I use a 2nd port for driving the anode transistors with an RLF instruction for shifting the "digit on" bits. But these pins are not loaded hardly at all since they're just base driving the transistors with a decent value base resistor on the pin.

My style of embedded circuit design is the design the circuit such that the uC's job is just to generate the required control signals but is buffered from the load itself. Probably a reason why I've never run into this issue.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top