Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help on the PIC16F628

Status
Not open for further replies.

Guyver

New Member
Hi all,
I got this probelm and was wondering if anyone can help me.
I got 2 PIR detectors that sends a pulse out to the PIC16F628 pin 17 n 18.
What i want the microcontroller to do is to figure out which of the 2 PIR's have been triggered and send out a string eg "CAMA" or "CAMB" through pin 8 through the serial port to the PC which ineracts with visual basic 6 (I can do the VB side just not the microcontroller)

Thank you for helping me, much appreciated

I have started the code, but i was wondering if ne1 can fill the gaps if i missed any. THANKS :lol:


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)

	MOVLW 0X07
	MOVWF CMCON

	BANKSEL TRISA
	MOVLW B'00100011'
	MOVWF TRISA

	MOVLW B'00000010'
	MOVWF TRISB

	BANKSEL SPBRG
	MOVLW D'12'
	MOVWF SPBRG

	MOVLW B'00100100'
	MOVWF TXSTA

	MOVLW B'00000000'
	MOVWF PIE1

;----------------------------------------------------------------------------
;						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
 
Tris B should be loaded with b'00000110' - Both the RX and TX pins have to be set as input in order for the hardware uart to work properly. (page 69 of 16f628 datasheet. section 12.0)

Then you have to set bit 7 (SPEN) of register RCSTA, wich enables the usart. (watch out. RCSTA is in another bank then TXSTA)

When sending you should check bit TXIF of register PIR1. It will be set when you're allowed to write to TXREG. Waiting for TRMT makes no sense since it is a status bit for the shift register. TXREG may already be empty when the shift register is still....shifting
 
:idea:

It may also be a good idea to sit in a loop after sending the data to make sure that the pin is low before returning to "START" otherwise you will get...... CAMACAMACAMACAMACAMACAMACAMACAMA (etc!)

Hope this helps!
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top