| Many IR receivers are designed to
work with remote controls that use a standard 38khz carrier
signal. The code below shows how to configure one of the M32's
16-bit timers to produce a 38khz square wave that can drive a IR
LED.
Sample Code
'Sample
38.5khz squarewave generator using a DevBoard-M32
'Running at 8mhz
'Configure Timer1
as
a counter using Compare Mode. When the count exceeds the value
'of Compare1a it
will toggle OC1A(PortD.5).
Config
Timer1
=
Counter
,
Edge =
Rising ,
Prescale =
8 ,
Compare A =
Toggle
'Change the value
of Compare1a to adjust the frequency
'Timer1 is a 16-bit timer, you can go up to 65535
Compare1a
=
102
'PortD.5 is the
output pin
Config
Pind.5
=
Output
Do
'Nothing
Loop
End
This code will generate a
squarewave that is about 38khz. Changing the value of Compare1a will
change the frequency of the squarewave. A higher value will
lower the frequency. To turn the squarewave off and on, use the Start
Timer1 and Stop Timer1
commands. |