Configure PORTA (Assembley)

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
When writing a program for a PIC in assembley, how do you configure PORTA as a digital input and use the stimulus to toggle the value of the pin RAO?

I have set TRISA to 00000001 and set ANSELA to 00000000 but when I fire the stimulus (On MPLAB and the stimulus is set tot toggle) no bit changes on PORTA.

Anyone know Assembely and MPLAB well?
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
Ok I'll take a look, I'm using the 12f1822 but I am trying to get it to work on the simulator before I worry about actually downloading to a Microcontroller so I just want to get it to work in MPLAB first
 

Markd77

Joined Sep 7, 2009
2,806
Is there something else that needs to be changed, like CMCON?
Also you won't see the port change until the next instruction, so toggle the bit, and single step to see if that makes any difference.
If not, post the code.
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
The PIC doesnt have a CMCON that I am aware of. According to the datasheet teh only registers related to PORTA are TRISA, LATA, ANSELA, WUA and INLVLA but I have only configured ANSELA and TRISA.

I set the 0th bit to 1 on both.

I haven't used BSR as I don't really understand what it does, but some tutorials state I need to use it. Could that be the problem?
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
include C:\pathtomyheaderfile\as12f1822.h


list p = 12f1822

TRISA equ 008Ch


;*******Main body of program**************************************************


movlw 0x01 ;
movwf BSR ;

movlw 0x01 ;
movwf TRISA ;

movlw 0x01 ;
movwf ANSELA ;

movlw 0x01 ;
movlw 0x01 ;
movlw 0x01 ;

END

I put the last 3 instructions in so I can try firing the input and then step through an instruction to see if it changed

I have the correct path to the header file on the actual code
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
I wanted to upload the header file aswell so you could simulate it in case you wanted to see how it runs but the forum won't upload .h files
 

ErnieM

Joined Apr 24, 2011
8,377
Does this actually build??? a dot-h file is for C programs. You want to include the dot-inc file for your PIC. Do search your microchip folder for 12F1822TEMP.ASM which is an outline of everything this PIC needs: every PIC has such a file and should be copied (leave the original intact for another project) and you can just start banging code into the area after "START."

Do look up the RAM bank selections. You need to change banks for different registers.

You also don't do any configuration word settings.

Finally, you will need to set the ANSELA bit for RA0 to 0 and not 1 to disable the analog functionality and read the pin as anything as zero.
 

Thread Starter

David_Baratheon

Joined Feb 10, 2012
285
It builds ok and does configure the registers the way I tell it to, but nothing happens when I trigger the input stimulus

what bank register to i need to set?

why do u think PORTA doesnt change when I fire the input? I changed ANSELA
 
Last edited:

t06afre

Joined May 11, 2009
5,934
The stimulus will not create any changes unless the port is read. Try to make a program that mirror the output of one port to some other port. Also as a beginner you should go for a PIC with 28 or 40 pins. It is kind of wrong that small PIC is more simple to learn than the larger ones
 

ErnieM

Joined Apr 24, 2011
8,377
It builds ok and does configure the registers the way I tell it to, but nothing happens when I trigger the input stimulus

what bank register to i need to set?

why do u think PORTA doesnt change when I fire the input? I changed ANSELA
Changed ANSELA to what?

As TRISA and ANSELA are in different banks it is impossible for your code to change them both: while TRISA is indeed in bank 1 ANSELA is in bank 3, and you never touch bank 3.

David, it is time to post your code again. The full .asm file, inside code tags please.

You get code tags with the button with the # icon.

BTW, using MPLAB sim before loading into a physical PIC is an excellent thing to do. Now let us help you get the other things straight to get the code to work.
 
Last edited:

MMcLaren

Joined Feb 14, 2010
861
It builds ok and does configure the registers the way I tell it to...
I just tried the code you posted and it doesn't assemble without errors... Could you benefit from some examples?

Regards, Mike

Rich (BB code):
;******************************************************************
;                                                                 *
;   Filename:                                                     *
;     Author:                                                     *
;       Date:                                                     *
;                                                                 *
;   12F1822 Experiment                           *
;                                                                 *
;                                                                 *
;      MPLab: 8.84    (tabs=8)                                    *
;      MPAsm: 5.44                                                *
;                                                                 *
;******************************************************************

    #include <P12F1822.INC>
    radix dec
    errorlevel -302
    list st=off

  __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _MCLRE_OFF & _IESO_OFF & _FCMEN_OFF
  __CONFIG _CONFIG2, _LVP_OFF & _PLLEN_OFF
;
; _PWRTE_OFF    default
; _CP_OFF    default
; _CPD_OFF    default
; _BOREN_ON    default
; _CLKOUTEN_OFF    default
;
; _WRT_OFF    default
; _STVREN_ON    default
; _BORV_LO      default
;

;******************************************************************
;  variables                                                      *
;******************************************************************
        cblock  0x20

        endc

;******************************************************************
;  main init                                                      *
;******************************************************************
    org    0x0000
init
    banksel    OSCCON        ; bank 1              |B1
    movlw    b'01111010'    ;                  |B1
    movwf    OSCCON        ; setup 16-MHz INTOSC          |B1
waitfs    btfss    OSCSTAT,HFIOFS    ; stable? yes, skip, else      |B1
    bra    waitfs        ; branch and wait          |B1
;
;  configure port I/O
;
    banksel    ANSELA        ; bank 3              |B3
    clrf    ANSELA        ; set digital I/O          |B3
    banksel    TRISA        ; bank 1              |B1
    clrf    TRISA        ;                  |B1
    bsf    TRISA,TRISA5    ; GP?/RX must be set to input      |B1
    banksel    LATA        ; bank 2              |B2
    clrf    LATA        ;                  |B2
    movlb   0               ; bank 0                          |B0

;******************************************************************
;  main loop                                                      *
;******************************************************************

loop
        bra     loop            ;                                 |B0


;******************************************************************
        end
 
Top