after the helps from the form members, I am able to run ,and set my I/O ports in the 18f1320, I can control all the outputs, but my input cannot be read
BTFSS PORTA,0
GOTO START
BSF PORTB,0
as per the above code when I press the portA,0 switch I should get the output at the portB,0 but I am not getting.
BTFSC PORTA,0
GOTO START
BSF PORTB,0
as per the above code once download the program I am getting the output at the portB,0 becaus the portA,0 switch is not pressed, but once I press the portA,0 switch, there should not be any output at the portB,0 but still the output is there.
i cannot find out the problem, my codes are bellow please help me,
list p=18F1320
include <p18F1320.inc> ;IF we use this not need to declare port address
radix hex
;----------------------------------------------------------------------
; cpu equates (memory map)
Status equ 0xFD8
PORTA equ 0xF80 ; define the potA address
PORTB equ 0xF81 ;
TRISA equ 0xF92
TRISB equ 0xF93
ADCON0 EQU 0XFC2
ADCON1 EQU 0XFC1
LATA EQU 0XF89
LATB EQU 0XF8A
;----------------------------------------------------------------------
org 0x000
CLRF PORTA ;clearing the output
MOVLW 0X00
MOVWF ADCON0
MOVLW 0X7F ;configure the A/D
MOVWF ADCON1 ;for digital inputs
MOVLW 0xFF
MOVWF TRISA,0
;MOVLW 0xD0 ;values used to set the port
;MOVWF TRISA
;MOVWF LATA ;'11111111'
CLRF PORTB ;clearing the output
MOVLW 0X70 ;
MOVWF ADCON1 ;digital I/O pins
MOVLW 0x00
MOVWF TRISB,0
;MOVLW 0XCF ;values used to set the port
;MOVWF TRISB
;MOVWF LATB ;'00000000'
Start
BTFSS PORTA,0
;BTFSC PORTA,0
GOTO Start
BSF PORTB,0
goto Start
END
18f1320 I/O ports
-
- Posts: 61
- Joined: Thu Dec 20, 2007 4:23 pm
- Location: singapore
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: 18f1320 I/O ports
Hello Saran
You are in Bank0 of memory.
To modify the TRIS registers you have to be in bank 1 of memory.
To change from bank 0 to bank 1 you have to set the RP0 bit in the status register, Refer to the device datasheet on how to do this.
Once you have modified the TRIS registers you can move back into Bank0 to control the I/O.
You are in Bank0 of memory.
To modify the TRIS registers you have to be in bank 1 of memory.
To change from bank 0 to bank 1 you have to set the RP0 bit in the status register, Refer to the device datasheet on how to do this.
Once you have modified the TRIS registers you can move back into Bank0 to control the I/O.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel