pic 18f1320

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
saravana_3
Posts: 61
Joined: Thu Dec 20, 2007 4:23 pm
Location: singapore
Contact:

pic 18f1320

Post by saravana_3 »

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
saran

User avatar
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

Post by Benj »

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.

saravana_3
Posts: 61
Joined: Thu Dec 20, 2007 4:23 pm
Location: singapore
Contact:

Re: pic 18f1320

Post by saravana_3 »

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

User avatar
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

Post by Benj »

Hello

It could be the capitalisation that it does not like. Try using all lower case or all upper case for your register names.

User avatar
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

Post by Steve »

MOVLW 0XFF ;values used to set the port
MOVWF TRISB ;'00000000'
Although the comments say you are setting TRISB to 0x00, you are in fact setting it to 0xFF (i.e. all inputs).

saravana_3
Posts: 61
Joined: Thu Dec 20, 2007 4:23 pm
Location: singapore
Contact:

Re: pic 18f1320

Post by saravana_3 »

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
saran

User avatar
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

Post by Steve »

If you want to use the pins on PortB as outputs, you need to set the TRISB register to 0x00.

User avatar
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

Post by Benj »

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.

User avatar
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

Post by Steve »

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:

Code: Select all

MOVLW 0x00
MOVWF TRISB, 0

Post Reply