![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| WHats wrong with this code? I cant seem to get anything to come out from the transmitter pin Please can u help Code:
LIST P = 16F628 ; MICROCONTROLLER USED
#include "P16F628.inc" ; HEADER FILE (CONTAINS APPROPRIATE EQUATES SECTION
;===========================================================================
; CONFIGURATION WORD
;===========================================================================
ERRORLEVEL 0, -302 ; STOPS BANK SELECTION MESSAGES
__CONFIG 0x3D18 ;CONFIGURATION WORD (SETS OSCILATOR ETC)
org 0x0000
bsf STATUS, RP0 ;select bank 1
MOVLW 0X07
MOVWF CMCON
MOVLW B'00100011'
MOVWF TRISA
MOVLW B'00000010'
MOVWF TRISB
MOVLW D'12'
MOVWF SPBRG
MOVLW B'00100100'
MOVWF TXSTA
MOVLW B'00000000'
MOVWF PIE1
MOVLW b'00100100'
MOVWF TXSTA ;configure USART transmission
clrf PIE1
bcf STATUS, RP0 ;return to bank 0
bsf RCSTA, SPEN
;----------------------------------------------------------------------------
; Main program
;----------------------------------------------------------------------------
START
BANKSEL PORTA
BTFSC PORTA, 0 ;Check to see if the carry is set
CALL CAMERA_A
BTFSC PORTA, 1
CALL CAMERA_B
GOTO START ;Loop forever
CAMERA_A
C_A
BANKSEL TXSTA
BTFSS TXSTA, TRMT
GOTO C_A
BANKSEL TXREG
MOVLW H'41'
MOVWF TXREG
RETURN
CAMERA_B
C_B
BANKSEL TXSTA
BTFSS TXSTA, TRMT
GOTO C_B
BANKSEL TXREG
MOVLW H'42'
MOVWF TXREG
RETURN
END | |
| |
| | (permalink) |
| :idea: change...... ;================================================= ========================== ; CONFIGURATION WORD ;================================================= ========================== ERRORLEVEL 0, -302 ; STOPS BANK SELECTION MESSAGES __CONFIG 0x3D18 ;CONFIGURATION WORD (SETS OSCILATOR ETC) org 0x0000 bsf STATUS, RP0 ;select bank 1 MOVLW 0X07 MOVWF CMCON etc........ to........ ;================================================= ========================== ; CONFIGURATION WORD ;================================================= ========================== ERRORLEVEL 0, -302 ; STOPS BANK SELECTION MESSAGES __CONFIG 0x3D18 ;CONFIGURATION WORD (SETS OSCILATOR ETC) org 0x0000 MOVLW 0X07 MOVWF CMCON bsf STATUS, RP0 ;select bank 1 etc...... You are not disabling the comparators, as you are trying to do this in page 1 (cmcon is in page 0), this data will be loaded into VRCON in your original code. hope this helps
__________________ Regards MATT! | |
| |
| | (permalink) |
| YEA it works now, thnaks m8. Just another qucik question while yer here, how u put a delay into the code for 2seconds and call it into camera a and camera b? Cos its checing it a couple of thausands of time every seconds | |
| |
| | (permalink) |
| :idea: START BANKSEL PORTA BTFSC PORTA, 0 ;Check to see if the carry is set CALL CAMERA_A BTFSC PORTA, 1 CALL CAMERA_B GOTO START ;Loop forever CAMERA_A C_A BANKSEL TXSTA BTFSS TXSTA, TRMT GOTO C_A BANKSEL TXREG MOVLW H'41' MOVWF TXREG LOOP_CAMA BTFSC PORTA, 0 ;HAS CAMERA A INPUT GONE LOW? GOTO LOOP_CAMA ;NO, LOOP UNTIL LOW RETURN This will keep the prog "trapped" after transmiting "CAMA" and only return when the line (input) has gone low again..... do the same for CAMB btw, it may not be a bad idea to comment your code abit more, this is not a go, just some advise, it helps others to help you (and to help yourself a few months later!) Hope this helps!
__________________ Regards MATT! | |
| |
| | (permalink) |
| ive done it CAMERA_B C_B BANKSEL TXSTA btfss TXSTA, TRMT goto C_B BANKSEL TXREG movlw H'42' movwf TXREG return LOOP_CAMB BTFSC PORTB, 0 ;HAS CAMERA B INPUT GONE LOW? GOTO LOOP_CAMB ;NO, LOOP UNTIL LOW RETURN does that not need a calling funtion? or does it do the loop straight after that bit of code?? sorry, i forgot about the comments, just wanted to get the thing working first :P | |
| |
| | (permalink) |
| WHOOPs, the code is meant to be like this, i forgot about changing the names Code: CAMERA_B
C_B
BANKSEL TXSTA
btfss TXSTA, TRMT
goto C_B
BANKSEL TXREG
movlw H'42'
movwf TXREG
LOOP_C_B
BTFSC PORTB, 0 ;HAS CAMERA B INPUT GONE LOW?
GOTO LOOP_C_B ;NO, LOOP UNTIL LOW
RETURN | |
| |
| | (permalink) |
| :?: Seems fine, have you swapped the input for camera B to port B,0 then? btw, a usefull way to keep track of what's on what ports is to assign equates, sorry if I am patronising you..... here's an example.... ;PORTA ASSIGNMENTS CAM_A EQU H'00' ;CAMERA A INPUT 1=ACTIVE ;PORTB ASSIGNMENTS CAM_B EQU H'00' ;CAMERA B INPUT 1=ACTIVE Now when checking for your camera you can write..... BTFSS PORTB,CAM_B ;IS CAMERA B ACTIVE? Looking at your comments in the previous equates anyone can see that CAM_B is set to PORTB,0 and that a logic 1 is active. It makes it much easier to read. There is another HUGE advantage to using equates....... lets say you have 20 instances of BTFSS PORTB,CAM_B......... You now want to change CAM_B input to PORTB,1....... In your old code you have to change all 20 instances of PORTB,0 to PORTB,1...... But with equates you simply....... ;PORTB ASSIGNMENTS CAM_B EQU H'01' ;CAMERA B INPUT 1=ACTIVE Recompile, and it's all done........ There are other features within MPLAB that allow you to use Macro's I avoid using these as I find they make the code difficult to read.....Each to their own!! Hope this helps!
__________________ Regards MATT! | |
| |
| | (permalink) |
| Or, even simpler #Define CameraB PORTB,0 and in your code you can write BTFSS CameraB | |
| |
| | (permalink) |
| :lol: You are correct, however, like I said, i personally, and it is just a personal thing, don't like using defines....... I have had to work with other peoples code that looks a bit like this (ok a BIT exagerated :wink: ) CAMERA_ON CAMERA_OFF RESET_TIMER CHECK_INTS You get the idea..... what do these mean??? you have to keep checking the defines, anyway, I suppose, in moderation (like none! :wink: ), they can be usefull (he admitted with "tounge-in-cheek") I am probably just too old to keep track of more than 1 thi........ what was I saying?? :wink:
__________________ Regards MATT! | |
| |