Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 11th June 2009, 04:19 PM   #1
Default rs232 problem

i was connecting rs232 DB9 to PIC16f877A and using hyperterminal to show the data. it only work when i keep on switching on and off power supply. it was no respond when i switch on the powerr supply constanly. anyone can tell me what is the problem ? below is my programming code.


unsigned short temp_res;

void main() {
USART_Init(19200);


ADCON1 = 0;
TRISA = 0xFF;
do {
temp_res = ADC_Read(2) >> 2;
USART_Write(temp_res);
Delay_ms(100);
} while (1);
}
tss is offline  
Old 11th June 2009, 05:48 PM   #2
Default

Quote:
Originally Posted by tss View Post
i was connecting rs232 DB9 to PIC16f877A and using hyperterminal to show the data. it only work when i keep on switching on and off power supply. it was no respond when i switch on the powerr supply constanly. anyone can tell me what is the problem ? below is my programming code.

Code:
unsigned short temp_res;

void main() {
  USART_Init(19200);


  ADCON1 = 0;
  TRISA  = 0xFF;
  do {
    temp_res = ADC_Read(2) >> 2;
    USART_Write(temp_res);
    Delay_ms(100);
  } while (1);
}


the while (1) at the end just loops there, so your program will run once and sit at the loop (if I remember correctly).

Last edited by binzer; 11th June 2009 at 05:49 PM.
binzer is offline  
Old 11th June 2009, 06:20 PM   #3
Default

so did you mean i have to change my program from

do{
..... } while (1);

to

while (1) {
..... };

it doenst work when i connected rs232 pin 2 (Rx) to MAX232 pin 14(T1out) without moving.
it work only when rs232 pin (Rx) keep on touching and removing from MAX232 pin 14(T1out).
once pin 2 touched pin 14, hyperterminal will shows the data then stop. to receive data continuously, i have to keep on touching and removing the pin. do you know what is the problem ?
tss is offline  
Old 12th June 2009, 06:12 AM   #4
Default

Quote:
Originally Posted by tss View Post
so did you mean i have to change my program from

do{
..... } while (1);

to

while (1) {
..... };

it doenst work when i connected rs232 pin 2 (Rx) to MAX232 pin 14(T1out) without moving.
it work only when rs232 pin (Rx) keep on touching and removing from MAX232 pin 14(T1out).
once pin 2 touched pin 14, hyperterminal will shows the data then stop. to receive data continuously, i have to keep on touching and removing the pin. do you know what is the problem ?
It sounds like a bad ground or a ground loop between the items. Can you post your circuit?
Do you have decoupling caps on the pic and MAX232? Is your power supply clean (noise)?
binzer is offline  
Old 14th June 2009, 07:32 PM   #5
Default schematic

this is my schematic. it only work when i unground pin 15. i also found that my hyperterminal received data without pic16f877. actually hyperterminal should not receive any data without pic16f877 am i right ?
Attached Files
File Type: doc Doc1.doc (108.5 KB, 37 views)
tss is offline  
Old 14th June 2009, 09:41 PM   #6
Default

Quote:
Originally Posted by tss View Post
so did you mean i have to change my program from

do{
..... } while (1);

to

while (1) {
..... };
No, it will work both ways. You can check the web for syntax.

Code:
  do {
    temp_res = ADC_Read(2) >> 2;
    USART_Write(temp_res);
    Delay_ms(100);
  } while (1);
I am guessing you expect to see the result of the ADC_Read display on hyperterminal.

Code:
void Usart_Write(unsigned short data);
If the ADC conversion returns 65 you will see the letter 'A' in hyperterm. 66 will result in 'B'. Because 65 is the ascii value for A and 66 is the ascii value for B.

You can either use printf which has the ability to convert you number to a string (ie 65 becomes the char 6 followed by the char 5) or itoa (int to ascii) to get a string of characters and use Usart_Write to send each out in order.

Both of these are somewhat compiler dependant and there is no mention of which complier you are using.

I did not look at the schematic.
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Old 14th June 2009, 11:50 PM   #7
Default

Quote:
Originally Posted by tss View Post
this is my schematic. it only work when i unground pin 15. i also found that my hyperterminal received data without pic16f877. actually hyperterminal should not receive any data without pic16f877 am i right ?
Picture is too fuzzy for me to see. I would disconnect the RX on the pic as you may be generating junk on the input, do you have interrupts shut off on the Usart?
Mike.
binzer is offline  
Old 15th June 2009, 06:40 AM   #8
Default

Quote:
Originally Posted by binzer View Post
Picture is too fuzzy for me to see. I would disconnect the RX on the pic as you may be generating junk on the input, do you have interrupts shut off on the Usart?
Mike.
i used the program below to test my hyperterminal but i found that my pic16f877a pin RC6/Tx and RC7/Rx dont have output voltage. that means max232 did not receive any data from pic16f877. what is the problem ?

unsigned short temp_res;

void main() {
USART_Init(19200); // Initalize USART (19200 baud rate, 1 stop bit, no parity...)

// Select Vref and analog inputs, in order to use ADC_Read
ADCON1 = 0; // All PORTA pins as analog, VDD as Vref
TRISA = 0xFF; // PORTA is input

do {
temp_res = ADC_Read(2) ;
USART_Write(temp_res); // Send ADC reading as byte
Delay_ms(100);
} while (1); // endless loop
}
tss is offline  
Old 15th June 2009, 10:24 AM   #9
Default

my circuit is currently working. the previous problems have been solved by changing capacitors and clock of pic16f877a and the program still remain the same.

now i want to add Rf transmitter to pin RC6/Tx (pic16f877a) in order to transmit program to another computer using hyperterminal. please let me know if i am wrong. i hope can receive some comments from seniors again. thanks
tss is offline  
Old 15th June 2009, 10:34 AM   #10
Default

Quote:
Originally Posted by 3v0 View Post
No, it will work both ways. You can check the web for syntax.

Code:
  do {
    temp_res = ADC_Read(2) >> 2;
    USART_Write(temp_res);
    Delay_ms(100);
  } while (1);
I am guessing you expect to see the result of the ADC_Read display on hyperterminal.

Code:
void Usart_Write(unsigned short data);
If the ADC conversion returns 65 you will see the letter 'A' in hyperterm. 66 will result in 'B'. Because 65 is the ascii value for A and 66 is the ascii value for B.

You can either use printf which has the ability to convert you number to a string (ie 65 becomes the char 6 followed by the char 5) or itoa (int to ascii) to get a string of characters and use Usart_Write to send each out in order.

Both of these are somewhat compiler dependant and there is no mention of which complier you are using.

I did not look at the schematic.
how if i want to transmit program using RF transceiver? can u give me some examples of transmitting program using RF transceiver? i am using microC compiler. i will connect RF receiver to computer using max232. i aim is to transmit program using RF transceiver and read the program on hyperterminal. please guide me.
tss is offline  
Old 15th June 2009, 11:21 AM   #11
Default

Quote:
Originally Posted by tss View Post
how if i want to transmit program using RF transceiver? can u give me some examples of transmitting program using RF transceiver? i am using microC compiler. i will connect RF receiver to computer using max232. i aim is to transmit program using RF transceiver and read the program on hyperterminal. please guide me.
Many people use Manchester Coding to send data over RF, it would have to be implemented in your pic code or I think there are some rf tranceivers capable of doing that also.
Mike.
binzer is offline  
Old 15th June 2009, 11:35 AM   #12
Default

Quote:
Originally Posted by binzer View Post
Many people use Manchester Coding to send data over RF, it would have to be implemented in your pic code or I think there are some rf tranceivers capable of doing that also.
Mike.
if i use hyperterminal, do i need to use manchester coding again? or i can just direct send data without manchester coding by hyperterminal ? can you give some examples as references for me ? i am using mikroC compiler currently.
tss is offline  
Old 15th June 2009, 11:52 AM   #13
Default

Quote:
Originally Posted by tss View Post
if i use hyperterminal, do i need to use manchester coding again? or i can just direct send data without manchester coding by hyperterminal ? can you give some examples as references for me ? i am using mikroC compiler currently.
Manchester Coding is used because it is more tolerant for non perfect transfer methods like rf or ir, you do not really need it for direct cable connections. If you encode it on one end you need to decode it on the other end. There may be info on Microchips site, but there have been postings on this before, check Nigels site as I believe he has info posted there.
Mike.

Check this thread.. RF module interface with PIC

Also here is a chip that does the job and can be used on both ends. http://www.rfmodules.com.au/rm/products/ctr124.htm

Last edited by binzer; 15th June 2009 at 12:07 PM.
binzer is offline  
Old 15th June 2009, 12:45 PM   #14
Default

Forget about radio until after you have it working with wires (RS232).

Neither of you have fixed the problem I pointed out in my previous post.
__________________
Please post questions to the forums. PM's are for personal communication.

BCHS/3v0's Tutorials
Junebug USB PIC programmer kit., USB Bit Whacker,
The 15 Minute Printed Circuit Board! (+drill time)
3v0 is online now  
Old 15th June 2009, 02:23 PM   #15
Default

Quote:
Originally Posted by 3v0 View Post
Forget about radio until after you have it working with wires (RS232).

Neither of you have fixed the problem I pointed out in my previous post.
Pardon me, I will refrain from further comments period.
binzer is offline  
Reply

Tags
problem, rs232

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
Firefly 16F88 RS232 problem futz Micro Controllers 6 23rd February 2008 01:04 PM
AVR DDS ~ RS232 problem... krazatchu AVR 15 13th December 2007 05:44 AM
rs232 problem handsprince General Electronics Chat 8 23rd April 2006 01:04 PM
Problem When Hooking RS232 Through A Y-Adapter ? iso9001 General Electronics Chat 2 16th March 2005 12:31 PM
PIC Basic Plus and RS232 problem again. Help!!! Beefer3 Micro Controllers 1 15th November 2003 12:08 AM



All times are GMT. The time now is 08:29 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker