View previous topic :: View next topic |
Author |
Message |
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 5:01 am |
|
|
hi im again,
now i wanna interface a pic16f876a my code is here
Code: |
#include <16F876A.H>
#fuses HS, NOWDT, NOPROTECT, NOBROWNOUT, NOPUT, NOLVP , NOCPD , NODEBUG
#use delay(clock=8000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,BRGH1OK,STOP=1)
void main()
{
int8 sec,min,hour;//day,date,month,year;
while(1)
{
//output_high(PIN_B2);
//delay_ms(1000);
output_low( PIN_B2);
//output_high(PIN_B3);
//delay_ms(1000);
//output_low( PIN_B3);
sec=00;
min=00;
hour=00;
putc(0x0c);
printf("Time : %02X:%02X:%02X\r\n",hour,min,sec);
// printf("Day : %02X\r\n",day);
//printf("Date : %02X/%02X/20%02X\r\n",date,month,year);
delay_ms(500);
}
} |
i tried with hyper termilnal but theres no output in hyperterminal.
[/img] |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Thu Oct 21, 2010 5:21 am |
|
|
Do you have a MAX232 or equal IC betwen the PIC and the PC ?
BTW pin 2 of the PC serial(if 9 pin) is receive ! |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 5:26 am |
|
|
yes i have max232 for connecting pc to uc |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 5:30 am |
|
|
i got voltage
on max232
are
pin11-4.89Vconnected to uc(Pin16/c6)
pin12-4.89Vconnected to DB9(Pin17/c7)
pin13- (-13V)connected to DB9(Pin3)
pin14- (-3.5V)connected to DB9(Pin2) |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 5:32 am |
|
|
oh i forgot to tell you about FUSES to program by smartpro
all fuses are disabled
HS oscillator is on
anyway thanks for reply |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 9:51 am |
|
|
does any body can give a suggestion??? |
|
|
Tom Smith
Joined: 21 Oct 2010 Posts: 2 Location: Orlando, FL
|
|
Posted: Thu Oct 21, 2010 11:21 am |
|
|
If I had your problem ( and I have had it, in the past, with PIC16F877) I would:
1. Check supply voltages on the PIC and on the MAX232. You have done that.
2. Use an oscilloscope to make sure that the oscillator is running.
2b. Make sure that the PIC is not being held in reset.
3. Make real sure that the hyperterminal is set correctly.
3. Use o-scope to see if anything is coming out of the TX pin on the PIC. Coming out of the PIC TX, I believe that the signal polarity should have idle state = HI. If nothing is coming from the TX pin, problem is in the PIC. If signal is present at TX pin of uP, then problem is in your circuit. If something is coming out from the TX pin, check that the shortest high or low period is equal to one baud period at 9600 baud.
4. Add a bit output from the uP on an unused pin. Set pin high at beginning of your code, before the printf. Set the pin low after the printf. The resulting pulse on the output pin will show that the code is running.
5. Read the PIC user manual. Make sure that you have the TX and RX pins set as input or output in accordance with the UART chapter in the PIC user manual.
6. You have a lot of options specified in your #use RS232 statement. Simplify that statement and use default values. For a test.
With these ideas, you may still not find the problem but will have spent some quality time with your project. While looking in these areas, you may find something else that needs fixing. Good luck.
Tom _________________ Tom Smith |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Thu Oct 21, 2010 11:23 pm |
|
|
Hi tom thanks for the reply.
yaap I have checked all the parameter except using o-scope.
I only checked the voltage.
I programmed it with led blinking and there is no problem with that. Means the led in pinb2 and pinb3 works fine only I can't find any output in ht
waiting for reply |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Sat Oct 23, 2010 2:27 am |
|
|
hai still now im stucked
any body can give a suggestion
Misel |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat Oct 23, 2010 7:21 am |
|
|
Re-check your wiring and the capacitors polarities in the RS232 transceiver pins, should read close to
+9V (Pin 2) and -9V (Pin 6) respectively.
Regarding your code, as soon as you switch on is executed in a time close to 7 milliseconds, then it enters
in sleep mode. The RS232 transceiver has an internal pump-charge module that still is waking up and did
not generated the needed +/- voltages to run.
To test this, add a delay before the printf or run your printf in a closed loop like this.
Code: |
#include <16F877.h>
#device ADC=8
#fuses PUT, XT, NOWDT, NOLVP, NOBROWNOUT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, bits=8, parity=N, errors)
void main()
{
char c;
while(1)
{
c = getc();
putc(c);
}
}
|
Regards |
|
|
misel0019
Joined: 04 Oct 2010 Posts: 53 Location: Dhaka
|
232 |
Posted: Sun Oct 24, 2010 7:40 am |
|
|
still have no output.
trying and trying
any way thanks for the reply
i did that but no output
one thing change that while i press a key frm keyboard hyperterminal curser becomes slow
Misel0019 |
|
|
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
|
Posted: Sun Oct 24, 2010 8:04 am |
|
|
Check in your device manager what com port you are using,
download putty from here : http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Click on session - serial (enter com) (enter baud).
If this doesn't work its your hardware. _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Sun Oct 24, 2010 12:13 pm |
|
|
Well another RS232 issue. For RS232 you must first become familiar with the word asynchronous. After that you wire up your MAX232. Next the word to remember is Polarity since charge pumps are about to generate negative voltages from positive DC. Check every capacitor polarity twice. Now don't even attempt to send chars from or to your PIC program its way to early. First send a Square wave ( high for 1 second low for one second out the pic tx pin). Write the PIC code to do this. Check ( with a voltmeter) as the wave goes into the MAX232 and again as it comes out inverted. Next loop back ( with a jumper) at the MAX232 PC connection PIn 2 and Pin3 of a DB9. The square wave can now be checked at the PIC rx pin with the voltmeter. Make sure the ground on your PIC is connected to the ground on your DB9. All being well at this point you remove the jumper and move to the next step. By now you know what asynchronous means so you are ready to put a #USE rs232 statement into your code for the first time You are aware that a printf takes time as does any code. The chars on the way to you have no respect whatsoever as to what your code is doing. You must catch them or lose them. The hardware has a limited buffer basically the char last received. I know a very short tight loop type program that sends out less chars than are being received will work without the advice that's next. The tight loop to catch characters is of little practicality.
That's where the #RDA isr and a circular buffer come in. The time spent in mastering this will produce a 1000% return versus the time that might be spent wondering why a char is dropped. Next the #USE RS232 has parameters read about them. Especially the ERRORS parameter.
IF PCM programmer got a dollar for every time he points to ERRORS as being a good idea he'd have enough money to buy a small country.
Over the past decade or more PCM programmer and others have transferred accurate information to us all. I for one couldn't be more grateful. All of us that see the successful completion of a project only see it because we stand on the shoulders of these special individuals. |
|
|
dbotkin
Joined: 08 Sep 2003 Posts: 197 Location: Omaha NE USA
|
|
Posted: Sun Oct 24, 2010 4:27 pm |
|
|
To see if your RS232 hardware and PC terminal software is working, unplug your PIC and jumper pins 11 & 12 on the Max232. You should be able to type on the PC and see characters echoed back to you. If that works, then your PC and MAX232 are OK. If not, fix that first. And jacqueskleynhans is right, Putty is WAY better than Hyperterminal. Use it, you'll never go back to Hyperterminal.
And if your MAX232 isn't working, save yourself a couple of bucks and do this instead... http://www.botkin.org/dale/rs232_interface.htm |
|
|
|