![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Leon Guest
|
PIC Code Help |
Posted: Wed Apr 29, 2009 3:06 pm |
|
|
I am working on a project for my class. The hardware part of the project is completed, and we have a working prototype with 1 sensor input.
This means that our PIC MC is programmed for one input but we need a total of three. Currently the data input is serial analog, the MC converts it to digital and sends it to a transmitter. On the receiver end, the MC is programed to take the incoming data and convert it into parallel output which, using a DAC, is converted back into analog.
I have searched and searched for information on how to program the MC so that 3 inputs can be used. The three inputs have to be turned into serial data which is transmitted to the receiver. On this side, the MC has to take the data and output it in parallel for the DAC to convert back to analog.
The MicroController is: PIC16F688
Compiler: PICkit2
Thank you for any help!
The current code for transmitter side:
Code: |
#include <p16F688.inc>
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC
org 0
Start:
; Initialize registers
; bsf STATUS,RP0 ; select Register Bank 1
; bcf TRISA,0 ; make IO Pin RD0 an output
; bcf STATUS,RP0 ; back to Register Bank 0
bsf STATUS,RP0 ; select Register Bank 1
BSF TRISA,0
BSF ANSEL,0
bcf STATUS,RP0 ; select Register Bank 0
BSF RCSTA,7
; Configure ADCON0,ADCON1
bcf STATUS,RP0 ; back to Register Bank 0
MOVLW B'00000001'
MOVWF ADCON0
bsf STATUS,RP0 ; select Register Bank 1
MOVLW B'00000000'
MOVWF ADCON1
bcf STATUS,RP0 ; back to Register Bank 0
; Configure TXSTA
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'10100010'
MOVWF TXSTA
; Configure SPBRG
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'10000001'
MOVWF SPBRG
; Configire BAUDCTL
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'01000000' ; The transmit problem was here. If bit 0 is a 1, transmitter won't work
MOVWF BAUDCTL
MainLoop:
bsf ADCON0,1 ; Start conversion
btfsc ADCON0,1
goto $-1
; result in ADRESH
MOVF ADRESH,0
;MOVLW b'00010010' ; For debugging
MOVWF TXREG
goto MainLoop ; Do it again...
end
|
The Receiver side MC:
Code: |
; Make sure MPLAB is configured correctly
; - Choose the correct PIC
; - Go to Configure - Select Device
; - Select PIC16F688
; - Choose the correct programmer
; - Go to Programmer -> Select Programmer -> PICkit 2
; To load program onto PIC:
; - Go to Project -> Quickbuild
; - If no errors occur, download the code (*note there is a limit to the length of the filename, will cause error)
; - Go to Programmer -> Program
; - If no errors, remove the chip and place in circuit
TEMP equ 0x20
#include <p16F688.inc>
__CONFIG _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _EC_OSC
org 0
Start:
;Configure TRISA
bsf STATUS,RP0 ;select Register Bank 1
MOVLW B'00000000' ;Make outputs
MOVWF TRISA
;Configure TRISC
bsf STATUS,RP0 ;select Register Bank 1
MOVLW B'00100000' ;Make only RC0:4 Outputs as RC 5 is needed for Reciever
MOVWF TRISC
;Configure ANSEL
bsf STATUS,RP0 ;select Register Bank 1
MOVLW B'00000000' ; Set as Digital Signals
MOVWF ANSEL
;Configure PIE1
; bsf STATUS,RP0 ;select Register Bank 1
; MOVLW B'00100000' ;Allows Interrupt on Reciever
; MOVWF PIE1
;Configure INTCON
; bsf STATUS,RP0 ;select Register Bank 1
; MOVLW B'11000000' ;Allows Reciever Interrupt to Enable
; MOVWF INTCON
; Configure TXSTA
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'10000010'
MOVWF TXSTA
; Configure SPBRG
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'10000001'
MOVWF SPBRG
; Configire BAUDCTL
bcf STATUS,RP0 ; select Register Bank 0
MOVLW B'01000000'
MOVWF BAUDCTL
; Configure RCSTA
bcf STATUS,RP0 ;select Register Bank 0
MOVLW B'10010000'
MOVWF RCSTA
; Configure CMCON0
bcf STATUS,RP0
MOVLW B'00000111'
MOVWF CMCON0
bcf STATUS,RP0 ;select Register Bank 0
MainLoop:
btfss PIR1,5 ;Check bit 5 for full interrupt flag
goto $-1
; MOVLW B'10010011' ; Debugging
MOVF RCREG,0
MOVWF TEMP ; Move data to Temporary
MOVWF PORTA ; Move data to PORTA bits 2,1,0
; Move data bit 7 to PORTA,4
BTFSS TEMP,7
BCF PORTA,4
BTFSC TEMP,7
BSF PORTA,4
; Rotate and move to PORTC bits 3,2,1,0
RRF TEMP,1 ;Rotate working register 3 times
RRF TEMP,1
RRF TEMP,1
MOVF TEMP,0 ;Move High bits to Working Register
MOVWF PORTC ;Write 5 High Bits to port C's Low 5 Bits
goto MainLoop ; Do it again...
end
|
|
|
![](templates/subSilver/images/spacer.gif) |
Leon
Joined: 29 Apr 2009 Posts: 2
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
![](templates/subSilver/images/spacer.gif) |
Leon
Joined: 29 Apr 2009 Posts: 2
|
Re: PIC Code Help |
Posted: Wed Apr 29, 2009 3:14 pm |
|
|
Thank you for quick response, and for pointing me in the right direction. This could explain why I could not find anything, looking under wrong code.
Thank you again |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|