Hi friends
I am using the pic18f1320, with assembly labguage, last two weeks I am strugling to set the I/O ports and configure the chips, but always failure,below is my code please correct my mistakes, am I need to do any configuration settings, pllease share your expperience.
; setup configuration bits
;
;config OSC = RC ; External RC on OSC1, OSC2 as FOSC/4
;config FSCM = OFF ; Fail-Safe Clock Monitor disabled
;config IESO = OFF ; Internal External Switch Over mode disabled
;config PWRT = OFF ; Power up timer disabled
;config BOR = OFF ; Brown out reset disabled
;config WDT = OFF ; Watch dog timer off
;config MCLRE = OFF ; MCLRE off (pin available for input)
;config LVP = OFF ; Low voltage programming disabled
;config DEBUG = OFF ; Background debugger off
list p=18F1320
radix hex
;----------------------------------------------------------------------
; cpu equates (memory map)
Status equ 0xFD8
portA equ 0xF80 ; define the potA address
portB equ 0xF81 ;
ADCON1 EQU 0XFC1
;----------------------------------------------------------------------
org 0x000
CLRF portA ;clearing the output
MOVLW 0X00 ;configure the A/D
MOVWF ADCON1 ;for digital inputs
MOVLW 0x00 ;values used to set the port
MOVWF TRISA ;'11111111'
CLRF portB ;clearing the output
MOVLW 0X00 ;
MOVWF ADCON1 ;digital I/O pins
MOVLW 0XFF ;values used to set the port
MOVWF TRISB ;'00000000'
Start
bsf portB,0
bsf portB,1
bsf portB,2
bsf portB,3
bsf portB,4
bsf portB,5
bsf portB,6
bsf portB,7
goto Start
END
pic 18f1320
-
- 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: pic 18f1320
Hello Saran
It will make it easier for you if you learn how to deal with the error messages.
Please can you tell me what error messages you are receiving when trying to compile your code.
It will make it easier for you if you learn how to deal with the error messages.
Please can you tell me what error messages you are receiving when trying to compile your code.
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
-
- Posts: 61
- Joined: Thu Dec 20, 2007 4:23 pm
- Location: singapore
- Contact:
Re: pic 18f1320
there is no error messagae after declare all the port address, able to compile and download in to the development kit but, there is no output at the portB LED.
saran
- 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: pic 18f1320
Hello
It could be the capitalisation that it does not like. Try using all lower case or all upper case for your register names.
It could be the capitalisation that it does not like. Try using all lower case or all upper case for your register names.
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
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: pic 18f1320
Although the comments say you are setting TRISB to 0x00, you are in fact setting it to 0xFF (i.e. all inputs).MOVLW 0XFF ;values used to set the port
MOVWF TRISB ;'00000000'
-
- Posts: 61
- Joined: Thu Dec 20, 2007 4:23 pm
- Location: singapore
- Contact:
Re: pic 18f1320
hi,
thanks I followed all of your advise but still the same,my ammended codes again.
; setup configuration bits
;
;config OSC = RC ; External RC on OSC1, OSC2 as FOSC/4
;config FSCM = OFF ; Fail-Safe Clock Monitor disabled
;config IESO = OFF ; Internal External Switch Over mode disabled
;config PWRT = OFF ; Power up timer disabled
;config BOR = OFF ; Brown out reset disabled
;config WDT = OFF ; Watch dog timer off
;config MCLRE = OFF ; MCLRE off (pin available for input)
;config LVP = OFF ; Low voltage programming disabled
;config DEBUG = OFF ; Background debugger off
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
org 0x05
;CLRF portA ;clearing the output
MOVLW 0X00
MOVWF ADCON0
MOVLW 0X7F ;configure the A/D
MOVWF ADCON1 ;for digital inputs
MOVLW 0xFF ;values used to set the port
MOVWF PORTA ;MOVWF LATA ;'11111111'
;CLRF portB ;clearing the output
MOVLW 0X7F ;
MOVWF ADCON1 ;digital I/O pins
MOVLW 0X00 ;values used to set the port
MOVWF PORTB
;MOVWF LATB ;'00000000'
Start
bsf PORTB ,0
bsf PORTB ,1
bsf PORTB ,2
bsf PORTB ,3
bsf PORTB ,4
bsf PORTB ,5
bsf PORTB ,6
bsf PORTB ,7
goto Start
END
thanks I followed all of your advise but still the same,my ammended codes again.
; setup configuration bits
;
;config OSC = RC ; External RC on OSC1, OSC2 as FOSC/4
;config FSCM = OFF ; Fail-Safe Clock Monitor disabled
;config IESO = OFF ; Internal External Switch Over mode disabled
;config PWRT = OFF ; Power up timer disabled
;config BOR = OFF ; Brown out reset disabled
;config WDT = OFF ; Watch dog timer off
;config MCLRE = OFF ; MCLRE off (pin available for input)
;config LVP = OFF ; Low voltage programming disabled
;config DEBUG = OFF ; Background debugger off
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
org 0x05
;CLRF portA ;clearing the output
MOVLW 0X00
MOVWF ADCON0
MOVLW 0X7F ;configure the A/D
MOVWF ADCON1 ;for digital inputs
MOVLW 0xFF ;values used to set the port
MOVWF PORTA ;MOVWF LATA ;'11111111'
;CLRF portB ;clearing the output
MOVLW 0X7F ;
MOVWF ADCON1 ;digital I/O pins
MOVLW 0X00 ;values used to set the port
MOVWF PORTB
;MOVWF LATB ;'00000000'
Start
bsf PORTB ,0
bsf PORTB ,1
bsf PORTB ,2
bsf PORTB ,3
bsf PORTB ,4
bsf PORTB ,5
bsf PORTB ,6
bsf PORTB ,7
goto Start
END
saran
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: pic 18f1320
If you want to use the pins on PortB as outputs, you need to set the TRISB register to 0x00.
- 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: pic 18f1320
Hello
To convert the pins to outputs you must first set the RP0 bit in the status register. This will place you into bank 1 of the register memory. Then assign the trisb register a value of 0x00 for all outputs. Next clear the RP0 bit in the status register to move back to bank 0.
Once you have done this your outputs to the portb will now work correctly.
To convert the pins to outputs you must first set the RP0 bit in the status register. This will place you into bank 1 of the register memory. Then assign the trisb register a value of 0x00 for all outputs. Next clear the RP0 bit in the status register to move back to bank 0.
Once you have done this your outputs to the portb will now work correctly.
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
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: pic 18f1320
18F devices do not use RPx bits in the STATUS register. You can access them directly using the "access bank".
To set the pins as outputs, use:
To set the pins as outputs, use:
Code: Select all
MOVLW 0x00
MOVWF TRISB, 0