PDA

View Full Version : Remote control with frequencies



tohu thomson
- 15th August 2007, 05:46
Hello
I'm sory my english language is not good.

I built a circuit with pic16f628 and clock=4 mhz and:

_CP_OFF
_DATA_CP_OFF
_LVP_OFF
_BODEN_OFF
_MCLRE_OFF
_PWRTE_ON
_WDT_OFF
_XT_OSC

the circuit saves two signals in eeprom and then compares the received signal with the saved signal (+/- 10).
the first output opens when the received signal is corresponding to the saved signal,and the second do the same thing .
I have two inputs: the first RB6 is the signal input, and the second RB5 is the programming switch.
and the outputs are : RA1 and RA2.
in the first of code I read the eeprom.

I have the following problems:

1- the project is very slow, and it takes about 3 seconds to read the signal.
2- I want to make toggle outputs (in the first press on , the second off , the third on ,... and so on .but in my project the output opens for one second then closes and I failed to keep it open until the second press.
3- when I reboot the circuit it didn't work (don,t read eeprom or don't save ?).

this is my full code in mikrobasic:

Code:

program FC_TMR1_2

dim freq,freqL,freqH,data as word

dim freq1 as word absolute 0x30
dim freq1L as byte absolute 0x30
dim freq1H as byte absolute 0x31

dim freq2 as word absolute 0x32
dim freq2L as byte absolute 0x32
dim freq2H as byte absolute 0x33


dim T1 as word absolute 14
dim i,j,tmp as byte

sub procedure led1on
porta.1=1
end sub

sub procedure led2on
porta.2=1
end sub

sub procedure led1off
porta.1=0
end sub

sub procedure led2off
porta.2=0
end sub

sub procedure led1onoff
'porta=porta xor %00000010 'I use these manners but didn't work well
porta.1=not(porta.1)
end sub

sub procedure led2onoff
'porta=porta xor %00000100
porta.2=not(porta.2)
end sub

main:
porta=0
portb=0

trisa=%00000000
trisb=%01100000
OPTION_REG=%01010101
cmcon=0x07
intcon=0


'read eeprom
j=0
gosub read_code
freq1L=tmp

j=1
gosub read_code
freq1H=tmp

j=2
gosub read_code
freq2L=tmp

j=3
gosub read_code
freq2H=tmp

porta=$ff
portb=$ff
delay_ms(1000)
porta=0
portb=0

check_code:
freq=0

tmr1h=0
tmr1l=0
t1con=7
delay_ms(985)
t1con=0
freq = T1

freqL=freq-10
freqH=freq+10

CHECK1:
if freq1>=freqL then
if freq1<=freqH then
led1onoff
delay_ms(1000)
else
goto CHECK2
end if
else
goto CHECK2
end if

CHECK2:
if freq2>=freqL then
if freq2<=freqH then
led2onoff
delay_ms(1000)
else
goto prog_check
end if
else
goto prog_check
end if


prog_check:
if portb.5=1 then
delay_ms(2000)
goto enter_prog_mode
else
led1off
led2off
goto check_code
end if

enter_prog_mode:
led1on
led2on
delay_ms(1000)
led1off
led2off
delay_ms(1000)
led1on
led2on
enter2:
if portb.5=1 then
goto enter2
end if
led1off
led2off
Delay_ms(500)
led1on
led2on

prog_loop:
gosub count
freq1=freq
data=freq
i=0
gosub write_code
led1off
delay_ms(1000)
led1on

delay_ms(1000)
gosub count
freq2=freq
data=freq
i=2
gosub write_code
led2off
delay_ms(1000)
led2on
delay_ms(1000)
led1off
led2off

goto check_code

'************************************************* ****************
'************************************************* ****************
write_code:
eeprom_write(i,data)
return

read_code:
tmp=EEprom_read(j)
return


count:
if portb.6=1 then
delay_ms(100)
goto count2
else
goto count
end if

count2:
freq=0
tmr1h=0
tmr1l=0
t1con=7
delay_ms(985)
t1con=0
freq = T1
return

end.

Acetronics2
- 15th August 2007, 10:06
Hi, Tohu

The right address for your post is :

http://www.mikroe.com/forum/viewforum.php?f=10&sid=debb9fe1df8343339ac16ffd7f9c548f

Here it is PicBasicPro forum ... some help available, but about MKBasic its a bit trickier for us ...

Alain

tohu thomson
- 15th August 2007, 15:15
Thank you Alain
I send my problem to mikroe, many days ago, but no one answer me.