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.

still the same pic problems

Status
Not open for further replies.

kutalinelucas

New Member
could somebody please tell me any potential issues in using a pic 16f876a with a circuit and code designed for a 16f84.

it's only a simple design to blink a cursor on a hitachi lcd display, and it works perfectly fine on the 18 pin pic.
I read nigel Goodwins tutorial page on adopting code from a 16F628 - F976a pic, but i can't get it to work, and im coming to the end of my teather.
 
kutalinelucas said:
could somebody please tell me any potential issues in using a pic 16f876a with a circuit and code designed for a 16f84.

it's only a simple design to blink a cursor on a hitachi lcd display, and it works perfectly fine on the 18 pin pic.
I read nigel Goodwins tutorial page on adopting code from a 16F628 - F976a pic, but i can't get it to work, and im coming to the end of my teather.
The code should need little changes:

- change the GPR starting address
- care of configuring analog modules properly
- check the configuration word settings

I would suggest posting the code.
 
Your code with tags :)

Firstly get rid of the equates! The .inc does them for you.

Secondly don't use the hex config code if you want someone else to be able to read it.

Code:
;============LCD8.ASM===================
    list    P=16F876a                
    
    #include "P16F876A.inc"
    __config 0x3FF9
    radix    hex

[COLOR=Red][B] ;=======================================
;     cpu equates

    
status    equ    0x03
porta    equ    0x05
portb    equ    0x06
portc    equ    0x07
count1    equ    0x0c
count2    equ    0x0d
trisa    equ    0x85
trisb    equ    0x86
trisc    equ    0x87

;=======================================
;    bit equates
rp0    equ    5
;=======================================[/B][/COLOR]   
    org    0x000
;
start    bsf    status,rp0    ;switch to bank 1
    movlw    b'00000000'    ;outputs
    movwf    trisa
    movwf    trisb
    movwf    trisc
    bcf    status,rp0    ;switch back to bank0
    movlw    b'00000000'    ;all outputs low
    movwf    porta
    movwf    portb
    movwf    portc
    call    del_5        ;allow lcd time to initialise itself
    call    del_5
    call    initlcd        ;initialise display
circle    goto    circle        ;done
;=======================================
;=======================================
;=======================================
initlcd    bcf    portc,1        ;E line low
    bcf    portc,2        ;RS line low, setup for control
    call    del_125        ;delay 125 microseconds
    movlw    0x38        ;8-bit, 5x7
    movwf    portb        ;0011 1000
    call     pulse        ;pulse and delay
    movlw    0x0f
    movwf    portb        ;0000 1111
    call    pulse
    movlw    0x01        ;clear display
    movwf    portb        ;increment mode, no display shift
    call     pulse
    call    del_5        ;delay 5 milliseconds after init
    call    del_5
    return
;========================================

;==================================
del_125    movlw    0x2a        ;approx 42x3 cycles (decimal)
    movwf    count1        ;load counter
repeat    decfsz    count1,f        ;decrement counter
    goto    repeat        ;not 0
    return    
;==================================
del_5    movlw    0x29        ;decimal 40
    movwf    count2        ;to timer
delay    call    del_125        ;delay 125 micro seconds
    decfsz    count2,f    ;do it 40 times = 5 milliseconds
    goto    delay
    return            ;counter 0, ends delay
;==================================
pulse    bsf    portc,1        ;pulse E line
    nop            ;delay
    bcf    portc,1    
    call    del_125        ;125 micrsecond delay
    return
;==================================    
    end
;==================================
 
Last edited:
now it compiles with 21 errors ;-

Symbol not previously defined (status) etc...., and the inc file is in the same location as the txt file. any other sugesstions?
 
Last edited:
kutalinelucas said:
now it compiles with 21 errors ;-

Symbol not previously defined (status) etc...., and the inc file is in the same location as the txt file
The file p16f876a.inc has not been included properly.
BTW don't you save the code as type ".asm"?

Even if the code would be assembled, you should double-check the configuration word. The LVP is enabled for example, I guess you want to disable it? I would try with __CONFIG 0x3F39 but the hex format is not easily readable for me. Use the config labels instead.


Also, configure the ADCON1 register. If you'll modify the code in order to use PORTA as digital I/O this is necessary.


Code:
    ; ...

start    
    bsf    status,rp0    ;switch to bank 1
    
[B]    MOVLW 0x06 ; Configure all pins
    MOVWF ADCON1 ; as digital inputs [/B]   

    movlw    b'00000000'    ;outputs
    
    movwf    trisa
    movwf    trisb
    movwf    trisc

    ; ....

Check sections 4 and 14 in the datasheet for further details.
 
Last edited:
this is my first crack at any microcontroller programming, and am only going off a book i picked up yesterday, which compiled this code from a txt file, it worked correctly on a breadboard so i cant see how the inc. file is incorrectly included and going off the data sheets the config file codes are the same for both chips. Im not using porta for the moment - so the analouge imputs shouldnt cause a problem. i just want something to work!! anything even

since both controllers are in the same 14bit family. i really thought thered be lees involved in adopting or upgrading. I have been going in circles all day.
 
Last edited:
The old 16F84 had digital I/O lines (no analog input then). The new chips can do analog on them or digital (analog is the default). You need to set them to digital I/O lines.

Try setting ADCON1 to 7 before you run your code. That will make them digital I/O lines like the 16F84.

EDIT: some PICS you will need CMCON set to 7 (as I thought you mentioned the F87x chips but also mentioned Nigel's F628 tutorials). Another note, some pins are open collector so you might need a pullup on it. All depends on the chip. Look at the data sheet for that (like Port A pin 4 for example).
 
Last edited:
kutalinelucas said:
now it compiles with 21 errors ;-

Symbol not previously defined (status) etc...., and the inc file is in the same location as the txt file. any other sugesstions?

This will happen if you have case checking enabled in your build options, as the include file has the SFRs in upper case, and you have them in lower case in your asm file. For example: use STATUS rather than status.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top