Electronics Forum

Electronics Circuits & Projects discussion forum. Get help with electronics.


PIC Controller Help

Discuss about electronic circuits here. Request help for circuits that you couldn't find anywhere else, how a circuit works etc. Discuss anything related to electronic circuits.

Moderator: pebe

PIC Controller Help

Postby JoshMac » Tue Mar 15, 2016 3:37 pm

Hi Peoples,

Can anybody show me whats wrong with this code?!? The code appears to run fine, however, it will not allow me to change the TRISA or TRISB (TRIS A & B are stuck on 11111111). Programming in MPLAB 8.92. The code responds to virtual stimulus on the pins. Is there a register I am missing?

Thanks,
Josh

[size=50][code]
list p=16F628A ;SET CHIP MODEL
#include <p16F628A.inc> ;INCLUDE DEFAULTS
__CONFIG _CP_OFF & _WDTE_OFF & _BODEN_ON & _PWRTE_OFF & _LVP_OFF & _CPD_OFF & _INTOSC_OSC_NOCLKOUT & _MCLRE_OFF ;LOAD CONFIG SETTINGS
ORG 0x0000 ;SET ORIGIN TO 0X000

MOVLW 0X07 ;ALL COMPARATORS TO OFF
MOVWF CMCON
BSF STATUS,RP1 ;SELECT BANK0
MOVLW 0X00 ;SET PORT A DIRECTION
MOVWF TRISA
MOVLW 0x00 ;SET PORT B DIRECTOIN
MOVWF TRISB
CLRF INTCON ;SWITCH OFF ALL INTERUPTS
BCF STATUS,RP1 ;SELECT BANK0

START
MOVLW 0xFF
MOVWF PORTB
MOVWF PORTA

END
[/code][/size]
JoshMac
 
Posts: 27
Joined: Sun Dec 23, 2012 4:59 am
Location: Perth, Western Australia

Re: PIC Controller Help

Postby pebe » Wed Mar 16, 2016 10:08 am

It's because that's all you have asked the program to do.

After initializing the ports, your program begins at 'Start' with the instruction to load reg 'w' with FF. Then copy 'w' to both ports. There the program ends and you are left with FF at both ports.

How do you want to change them? As both ports are set as outputs you have no means to input a change.
pebe
 
Posts: 1058
Joined: Tue Dec 09, 2003 11:12 pm
Location: Ellon, Scotland

Re: PIC Controller Help

Postby JoshMac » Fri Mar 25, 2016 3:17 am

Hi Pepe,

The problem was that although I was asking it to change the TRIS A & B register, the change was not actually happening both in simulation and on board. After lots of playing around i found that it wasn't switching over to bank 1, so the process was effectively trying to change a reg called TRISA and TRISB in bank0 (which does not exist). Im not sure why, but i think it might have something todo with the include file, perhaps not understanding what "RP1" is. I changed it to modify the bit instead and everything appears to work.

As always - thanks for the help,
Josh
JoshMac
 
Posts: 27
Joined: Sun Dec 23, 2012 4:59 am
Location: Perth, Western Australia

Re: PIC Controller Help

Postby pebe » Fri Mar 25, 2016 12:26 pm

Hi Josh,
I'm glad you managed to sort it out. The problem was you were toggling RP1 to change banks, whereas you should have been toggling RP0.

If you look at page 17 of the data sheet for that PIC, you will see in Table 4-2 that RP0 and RP1 are bits of the Status register, which can be accessed from any bank. There are four banks (0 to 3) and RP1 selects either the top or bottom two, and RP0 determines whether banks 0/2 or 1/3 are selected.

Table 4-3 on page 20 shows the bits of the Status register. RP0 and RP1 are bits 5 and 6, so you could also change between bank 0 and 1 with 'SET STATUS,5' or 'RES STATUS,5'.

I hope that has helped.
pebe
 
Posts: 1058
Joined: Tue Dec 09, 2003 11:12 pm
Location: Ellon, Scotland


Return to Electronic Circuits Help



Who is online

Users browsing this forum: No registered users and 1 guest

14/3 Wire NM-B/250 Ft. Solid 100% COPPER indoor With Ground= Romex
$109.00
 14/3  Wire NM-B/250 Ft. Solid 100% COPPER indoor With Ground= Romex pictureBelden 8619 060 Multi-Cond. Cable, 19C, 18 AWG, 19x30, Gray, TC - 45 ft. Length
$375.00
Belden 8619 060 Multi-Cond. Cable, 19C, 18 AWG, 19x30, Gray, TC - 45 ft. Length picture100' Alpha 1232 SV005 Ground Braid Equivalent 12AWG Tinned Copper .375" Wide NEW
$299.87
100' Alpha 1232 SV005 Ground Braid Equivalent 12AWG Tinned Copper .375Carol C0600a.41.10 Computer Cable, Shielded, 24/1, 1000 Ft.
$368.99
Carol C0600a.41.10 Computer Cable, Shielded, 24/1,  1000 Ft. picture


cron