Maker Pro
Maker Pro

PIC16f877A Blinking an LED

Hello,

I am trying to blink an LED using the pic16F877A microcontroller and coding in assembly. The code looks fine to me but for some reason i am getting no output from the chip.

Code:
 RESET_VECTOR    CODE   0x0000     ; processor reset vector

INT_VECTOR    CODE    0x0004      ; interrupt vector location
   
BSF 03h,5   ;go to bank 1
MOVLW 00h   ;put 00000
MOVLW 85h   ;move 00000 to TRISA
BCF 03h,5   ;go back to bank 0
   
Start   movlw 02h  ;00010
    movwf 05h

    Loop1 decfsz 20h,1
      goto Loop1
      decfsz 21h,1
      goto Loop1
   
    movlw 00h
    movwf 05h
   
    Loop2 decfsz 20h,1
      goto Loop2
      decfsz 21h,1
      goto Loop2
     
    goto Start
   
END

The above is the code i am using in MPLAB X. I build it and the .hex file is generated and then i just program the chip using a programmer.
Any help ywould be greatly appreciated :)
 
I have not used that pic, but most come with the output set for analogue.
confirm with the manual. See ADCON1.
Also setting port for I/O. in the manual.
M.
 
Also it is preferred to use the .INC file for your pic, then you won't need to enter a register address, just the name.
M.
 
i noticed that that particular ouput i was using could also be an analouge input, however that being said i did configure that port as output. So i can change to a digital i/o port only RB1 and removed most of the code. just to perform a write. However nothing happend. the chip is programming successfully and also after programming i verified the data and it was correct. I don't understand, i also checked the status registor and i was selecting bank 1 to set the output pins.
 
Code:
RESET_VECTOR    CODE   0x0000     ; processor reset vector

INT_VECTOR    CODE    0x0004      ; interrupt vector location

BCF 0x03,6
BSF 0x03,5   ;go to bank 1
MOVLW 0x00   ;put 00000
MOVWF 0x86   ;move 00000 to TRISB
BCF 0x03,5   ;go back to bank 0
   
   movlw 02h  ;00010
    movwf 06h

END

This is the new code
 
It is much easier to follow when register names are used instead of addresses, when using the INC file.
M.
 
At the beginning of the program you create a list of equates.

Start with file(register) 20h call it del1 for delay 1 in your delay routine
21h is del2

now the set of equates becomes:

del1 equ 20h
del2 equ 21h

portA equ 5h


instead of

movlw 00h
movwf 05h

you can use a single instruction:

clrf portA

and then decf portA will put all "1's" on the port and turn everything ON!!!!!!!


Instead of writing the delay loop two times
Loop1 decfsz 20h,1
goto Loop1
decfsz 21h,1
goto Loop1


use:


Loop1 decfsz del1,1
goto Loop1
decfsz del2,1
goto Loop1
retlw 00


and call Loop1 on two occasions.
 
Thank you for your replies. Where can i find the .INC file ? I will organize the code and try again but i doubt that this will change anything because i am not chaning anything.
 
You can get it either from you Picmicro directory if you have downloaded the MPLAB IDE, or off the Picmicro site.
When running an application in MPLAB it goes under Header Files.
I am not saying it will change anything just makes it easier to program with register names instead of having to look up the address.
M.
 
Not tested but this is something to go on.
Look up the tutorials on the Nigel Goodwin site, shows the code you need.
Do a search of you program files dir for *.INC
M.

Code:
        CBLOCK 0x20 ; Start of General purpose registers
        STORE1
        STORE2
        endc
      

RESET_VECTOR    CODE   0x0000     ; processor reset vector
        goto    Goto Start1
INT_VECTOR    CODE    0x0004      ; interrupt vector location
Start1:
        bcf  STATUS, RP0 ;
        bcf  STATUS, RP1 ; Bank0
        clrf PORTA ; Initialize PORTA by
        ; clearing output
        ; data latches
        bsf STATUS, RP0 ; Select Bank 1
        movlw  0x06 ; Configure all pins
        movwf  ADCON1 ; as digital
  
;
        bsf STATUS RP1   ;go to bank 1
        clrf TRISA   ;put 00000
        bcf STATUS, RP0   ;go back to bank 0
  
Start:
        movlw 0x02  ;00010
        movwf PORTA

Loop1:
     decfsz STORE1
     goto Loop1
      decfsz STORE2
      goto Loop1
  
    clrf PORTA
  
  
Loop2:
         decfsz STORE1
          goto Loop2
          decfsz STORE2
           goto Loop2
    
    goto Start
  
   end
 
There is also running the Pickit 2/3 if that is what you are using in the debugger mode to step through the program.
M.
 
Sorry for the late reply but currently i'm doing exams lol. I have tried another controller but i got the same problem again. I don't know if it's the programming board, i am using a K150, but i ordered the one that is designed by microchip. When i receive it i'll try again and let you know. Thanks for your help everyone.
 
Set up PORTA as M said and just use banksel command for switching banks if you need to. Use molw b'00010, dont use HEX it gets confusing unless you know it very well. Then set up a delay and use the call funtion.

so:
main
bsf PORTA,1
Call delay
bcf PORTA,1
call delay
Return
 
Also in the OP you have used
MOVLW 00h ;put 00000
MOVLW 85h ;move 00000 to TRISA
All you did was clear W then move 85h to W , it did nothing to PORTA.
M.
 
Top