PDA

View Full Version : PIC12F635 - Any advise?



financecatalyst
- 20th July 2009, 17:57
Hello
I am new to pic programming. I have bought two RF modules and would like to make the link between them using my PIC12f635. I have written the following program for the transmitter:

//PROGRAM START

TRISIO=%011111
w1 VAR word
by var byte
cmcon0=%111
intcon=0
GPIO=0
Include "modedefs.bas"

START:
if gpio.0=1 then ZERO
IF GPIO.1=1 THEN ONE
IF GPIO.2=1 THEN Two
IF GPIO.4=1 THEN FOUR
GOTO START

ZERO:
serout GPIO.5,N2400,["abc",12]
pause 50
LOW GPIO.0
goto start
ONE:
serout GPIO.5,N2400,["abc",56]
pause 50
LOW GPIO.1
goto start
Two:
serout GPIO.5,N2400,["abc",90]
pause 50
LOW GPIO.2
goto start
FOUR:
serout GPIO.5,N2400,["abc",34]
pause 50
LOW GPIO.4
goto start

// program end

I WOULD LIKE TO KNOW HOW I CAN PLACE THE MCU IN POWERDOWN MODE UNTILL I PRESS A BUTTON?



//Receiver Program Start

TRISIO=%011111
pause 50
GPIO=0
pause 50
w1 VAR word
intcon=0
cmcon0=7
Include "modedefs.bas"
pause 50

start:
serin GPIO.2,N2400,100,start,["abc"],w1
pause 50
goto check
goto start
check:
if w1=12 then zero
if w1=56 then one
if w1=90 then four
if w1=34 then five
goto start

zero:
if w1=12 then
toggle gpio.0
pause 2000
else
pause 50
goto check
goto start
endif

one:
if w1=56 then
toggle gpio.1
pause 2000
else
pause 50
goto check
goto start
endif

four:
if w1=90 then
toggle gpio.4
pause 2000
else
pause 50
goto check
goto start
endif
five:
if w1=34 then
toggle gpio.5
pause 2000
else
pause 50
goto check
goto start
endif

//Program End

I WOULD LIKE AN EXPERT ADVISE ON THE RELIABILITY OF THE RECEIVER CODE BEFORE I USE IT TO CONTROL ANY MAINS DEVICE USING AN RELAY OR SCR.

(I am using PICBASICPro)

Thanks in advance for your replies. :)

aratti
- 20th July 2009, 18:20
I would reduce the code of Receiver Program in this way:




start:
serin GPIO.2,N2400,100,start,["abc"],w1

if w1=12 then zero
if w1=56 then one
if w1=90 then four
if w1=34 then five
goto start

zero:
toggle gpio.0
pause 2000
goto start

one:
toggle gpio.1
pause 2000
goto start

four:
toggle gpio.4
pause 2000
goto start

five:
toggle gpio.5
pause 2000
goto start

END


Remember decoupling cap (10nF) on the pic and snubber diodes on relays


Al.

financecatalyst
- 20th July 2009, 20:52
Thanks for the reply. But I still want to know how I can place the transmitter's MCU to power-down mode and wake it up once a key (on port A)is pressed and put it to sleep again once it has sent out the command? Can someone help me with the code changes -thanks :D

Archangel
- 21st July 2009, 01:56
Thanks for the reply. But I still want to know how I can place the transmitter's MCU to power-down mode and wake it up once a key (on port A)is pressed and put it to sleep again once it has sent out the command? Can someone help me with the code changes -thanks :D
Sleep
interrupt wake up , interrupt on change


'intcon.0 'RAIF PortA Interrupt Flag
'intcon.1 'INTF PORTA.2 INT Interrupt Flag
'intcon.2 'T0IF Timer 0 Interrupt Flag
'intcon.3 'RAIE PortA Interrupt Enable
'intcon.4 'INTE PortA.2 INT Interrupt Enable
'intcon.5 'T0IE Timer 0 Interrupt Enable
'intcon.6 'PEIE Peripheral Interrupt Enable
'intcon.7 'GIE Global interrupt enable

'enable Global interrupts GIE
'by setting bit 7
'enable on change interrupts
'by setting bit 3 RAIE
'Clear all interrupt flag bits
'bits 0,1,2,
'
intcon = 10001000
' tell it what to do when interrupt occurs
On Interrupt GoTo . . .
'clear the flag bit before going back to sleep
intcon.0 = 0
sleep
'or
@ sleep

check this link
http://www.picbasic.co.uk/forum/showthread.php?t=11325