|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
infrared and 16F77 |
Posted: Fri Sep 16, 2005 4:36 am |
|
|
hi,
i have problem in sending data via infrared. I use 16F77 PIC, pin A0 to detect switch press, pin C6 to send data to IR LED.
In between I use 12F675 to generate ~38khz freq with 27% duty cycle, and 74HC132 NAND Schmitt. For NAND ic, pin #1 for serial data, pin #2 38khz fed from 12F675, and out-pin # 3 to control 2N4403 PNP transistor, on/off.
Code for 38khz freq:
Code: |
#include <12F675.h>
#fuses xt, nomclr, noprotect, nowdt, nobrownout
#use delay(clock=4000000) // 4mhz clock
#define HH (output_high(PIN_A2))
#define LL (output_low(PIN_A2))
// 7us(high) + 16us(low) + 3.2us(overhead) = 26.2us
// so, freq = 1/26.2us = 38.16khz ~ 38khz
// *** 3.2us got this info from one of the probs posted, i guess...
#define t_high 7
#define t_low 16
void main() {
while(1) {
// clock = 4,000,000
// system timing = 1/4meg/4 = 1us
HH;
delay_cycles(t_high); // 7us high
LL;
delay_cycles(t_low); // 16us low
}
}
|
Code for txmitter:
Code: |
#include <16F77.h>
#fuses hs, noput, noprotect, nobrownout, nowdt
#use delay(clock=9830400)
#define SEND (!input(PIN_A0)) // switch pressed!
#use rs232 (baud=1200, xmit=PIN_C6, rcv=PIN_C7)
void main() {
const char c='a';
while(1) {
if(SEND) {
putc(c);
delay_ms(250); // debounce
}
}
}
|
when I power up the circuit, output from C6 (to NAND pin #1) always 'high' (is this their default state?) ...[1 nand 1 = 0], it will NAND'ed with the input from 38khz freq (NAND pin #2).
so, when I monitor the output (NAND pin #3) using Os-cope, it always turn on/off the 4403.
any help? thanks. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 16, 2005 11:56 am |
|
|
The idle state for the transmit pin on the Hardware USART is a high level.
To see this, go to the 16F77 data sheet, look in section 10.0 on the USART
and go to Figure 10-2. It shows Pin C6 in a high level idle state, and
when it does a start bit, it goes to a low level.
If you want to make an inverted output UART, then you'll have to
insert an inverter IC in there, or you could configure pins C6 and C7
as a software UART and then use the INVERT parameter. Maybe
you should do that initially, as a proof of concept. Example:
Code: | #use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, FORCE_SW, INVERT) |
Of course, you must have a version of the compiler that supports
the FORCE_SW parameter. If you have an earlier version, you
can do it by breaking the #use rs232 statement up into two separate
statements, one for xmit and one for rcv. Then it will become a
soft UART. |
|
|
Guest
|
|
Posted: Sun Sep 18, 2005 7:24 pm |
|
|
thank you PCM Programmer! it works. by the way, is it possible if I want to implement this code
Code: |
#use rs232(baud=1200, xmit=PIN_C6, rcv=PIN_C7, FORCE_SW, INVERT)
|
to other PICs as well? e.g 16F84A
Quote: |
If you have an earlier version, you
can do it by breaking the #use rs232 statement up into two separate
statements, one for xmit and one for rcv. Then it will become a
soft UART.
|
can u show me an example or is this what u mean
Code: |
#use rs232(baud=1200, xmit=PIN_C6, FORCE_SW, INVERT)
#use rs232(baud=1200, rcv=PIN_C7)
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Sep 18, 2005 8:57 pm |
|
|
The 16F84a has no hardware UART. CCS always makes a software
UART on any pins you specify. You don't need the FORCE_SW parameter.
There is no need to break up the #use rs232 statement into two
statements.
-----------
If you have more questions beyond this, then post the version of your
compiler. This will be a number such as 2.734, 3.191, or 3.234 etc. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|