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.

Code Won't Affect PORTA

Status
Not open for further replies.

ormo

New Member
Hi,

I am using the following code to multiplex a 7x8 LED array. PORTA (0x05) controls which column is on and PORTB (0x06) controls the rows for each column using the values in COL1 - COL8. PORTB changes exactly as it should to show the patterns, however PORTA remains on b'00000000'. I have also tried to us BSF and BCF to turn on individual bits in PORTA but that doesn't work either.

Code:
MULTIPLEX
    CLRF 0x05 ; Turn off columns
    CLRF 0x06 ; Turn off rows
    MOVLW b'00000001'
    MOVWF 0x05 ; Turn on column 1
    MOVF COL1,W
    MOVWF 0x06 ; Turn on rows for column 1
    NOP
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 2
    MOVF COL2,W
    MOVWF 0x06 ; Turn on rows for column 2
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 3
    MOVF COL3,W
    MOVWF 0x06 ; Turn on rows for column 3
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 4
    MOVF COL4,W
    MOVWF 0x06 ; Turn on rows for column 4
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 5
    MOVF COL5,W
    MOVWF 0x06 ; Turn on rows for column 5
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 6
    MOVF COL6,W
    MOVWF 0x06 ; Turn on rows for column 6
    CLRF 0x06 ; Turn off rows
    RLF 0x05,1 ; Turn on column 7
    MOVF COL7,W
    MOVWF 0x06 ; Turn on rows for column 7
    CLRF 0x05 ; Turn off columns
    CLRF 0x06 ; Turn off rows
    RETURN

Also, please don't make comments about using EQUs to get rid of annoying HEX codes as this is the way I prefer to program.

Thanks!
 
hi,

The PIC type and the PORTS initialising code would help.:)
 
Sorry... been a long day...

It's written for a PIC16F628A

Ports are set up as:

Code:
    BSF 0x03,5 ; Move to bank 1
    MOVLW 0x00
    MOVWF 0x85 ; Set PORTA to all outputs
    MOVWF 0x86 ; Set PORTB to all outputs
    BCF 0x03,5 ; Move to bank 0
 
Last edited:
Indeed - have you set PORTA to digital instead of analogue/comparator inputs ?
Have you set the port direction to outputs ?
Have you remembered that certain lines on PORTA are open drain or input only ?
 
Sorry... been a long day...

It's written for a PIC16F628A

Ports are set up as:

Code:
    [B]BSF 0x03,5 ; Move to bank 1[/B]
    MOVLW 0x00
    MOVWF 0x85 ; Set PORTA to all outputs
    MOVWF 0x86 ; Set PORTB to all outputs
    BCF 0x03,5 ; Move to bank 0

hi,
Is this correct.????? BSF 0x03,5 ; Move to bank 1

Woops I am looking cross eyed.:eek:

I know you prefer to code using the hex port/reg addressess, but its a little confusing.
 
Last edited:
Yeah, that bit of code is correct. 0x03 is the STATUS register and setting bit 5 moves us to bank 1.
 
What about the post I made above about setting the PORTA to digital and turning off comparators/analogue etc ?
 
Yeah, that bit of code is correct. 0x03 is the STATUS register and setting bit 5 moves us to bank 1.

Well it's an utterly silly way to carry on - use the MicroChip include file - you're just going to make silly mistakes doing it like that, and people mostly won't bother looking at your code.
 
hi,
Sorry about that, I have now edited the code using the PORTA/B equates etc.
Ran it in my SIM. only time PORTA is called [COL] is COL1.

It would appear the MULTIPLEX code for PORTA is all screwed up.

I'll look thru it.

EDIT: Look at this
Code:
MULTIPLEX
    CLRF PORTA ; Turn off columns
    CLRF PORTB ; Turn off rows

    MOVLW b'00000001'
    MOVWF PORTA ; Turn on column 1,

   [B] MOVF COL1,W;load COL1 into W, BUT [COL1] is empty.!
[/B]

EDIT2:
The rotate is clearing PORTA. see image
 

Attachments

  • esp01 Dec. 14.gif
    esp01 Dec. 14.gif
    8.9 KB · Views: 155
Last edited:
hi ormo,
I would recommend that you consider switching to the more conventional ways of writing your code, yours takes me back to the 1970's!.:), its very difficult to follow.
 
A couple of observations about your code,

You don't have a delay between subsequent rows.
You may shift a 1 bit into whichever port 0x05 is as you don't clear the carry flag.

I also agree with all the above, use the register names. If you write bsf 0x23,5 with the comment "set the carry flag" I am not going to go check the data sheet to see if that is correct. If you write bsf STATUS,C then I know it is correct.

Mike.
 
Include me among them

...and people mostly won't bother looking at your code.

Nigel is right; I did not.
 
Thanks to all for the advice - it's all going good now ;)
 
Thanks to all for the advice - it's all going good now ;)

hi ormo,
Can you tell us what changes you made to the code.? in order to make it work.:)
 
Last edited:
hi ormo,
Can you tell us what changes you made to the code.? in order to make it work.:)

Let me guess. It's the disabling of analog comparators?

movlw 0x07
movwf CMCON ;turn comparators off (make it like a 16F84)

From Nigels excellent tutorials: "Lines 5 and 6 are specific to the 16F628, 'movlw 0x07' means 'MOVe the Literal value 7 into the W register', the W register is the main working register, 'movwf CMCON' means 'MOV the value in W to File CMCON', CMCON is a register in the 16F628 that is used to select the operation of the comparator hardware. So these two lines set CMCON to 7, this disables the comparator, and makes their I/O lines available for general use."

Don't know the adress of CMCON, but I think that issue has been highlighted earlier...
 
Good guess by me then (on two posts above) :p

Glad you got it sorted :)

How disappointing, I thought you were inspired, not just guessing.:rolleyes:

Regards

Thanks 'ormo' your feedback will help others.:)
 
Last edited:
How disappointing, I thought you were inspired, not just guessing.:rolleyes:

Well without spending too much time trying to translate his code I had a quick glance over and decided I couldn't see anywhere that he'd turned off the comparators and/or A2D so thought it would be worth putting the solution that catches most of us out at one point or another up.

I think his next question will be about RA4 (and possible RA5) not working properly ........ ;)
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top