Here goes my code for 16F676. Used this IC because I can program it in PICKIT2 & also I have jumpered my sensor around it.
Code:
Include "modedefs.bas"
DEFINE NO_CLRWDT 1
DEFINE OSC 4 ' OSCCON defaults to 4MHz on reset
DEFINE OSCCAL_1K 1
@ __Config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP & _CPD
PAUSE 50
Tx Var PortA.1
Rx Var PortA.0
power var PortC.1
TRISA = %000001
TRISC = %000001
CMCON = 7
ANSEL = 0
OPTION_REG = %10000111 ' RAPU = off, PS 1:256 to TMR0
PORTA=0
PORTC=0
' setup iZCD to interrupt on change
INTCON = 0
; PortC.0 = PWM Receive ; ; ; ; ; PortC.1 = Power_On ; ; ; ; PortA.0 = Receive Pin ; ; ; ; PortA.1 = Transmit Pin ; ; ; ; PortA.2=Trigger Pin
main:
High power
pause 100
Serout Tx, N9600, ["0x44+0x00+160+ ???"] ; To set lower threshold distance to appx 3 meters. What should be the SUM & how do you calculate it?
Serout Tx, N9600, ["0x44+0x01+250+ ???"] ; To set upper threshold distance to appx 5 meters
Serout Tx, N9600, ["0x44+0x02+0xaa+ ???"] ; To set operation mode to autonomous mode
if PortA.2=0 then
High PortC.2 ; led 1
else
high PortC.5 ; led 2
endif
goto main
end
1) How do you calculate the SUM? any example please
Once I get to the next point, I will update here if I get stuck. Thanks
Bookmarks