tonyyy
Member level 1
- Joined
- Dec 26, 2012
- Messages
- 38
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,663
Hello guys.
I am trying to send chars to pic16876a using max232N (texas).
The simulation with proteus works just fine but with real circuit I am
facing with some strange beaviors. I have the following connections:
DB9 Connector <-> MAX232N
2 -> 14
3 -> 13
5-> gnd 15
max232n - PIc16876A
11 -> 17
12 -> 18
By using Terminal software I can see that max232 and cable are working. Infact
if I stick 11 and 12 togheter on max232 I got the
echo string in Terminal.
The firmare in pic is a simple Hitec C program which should give
me back data, here it is:
The rs232 parameters are the same. What's wrong?
When i power on the pic I should get the led blinking on port b, but it doesn't. Components are 10Mhz 22pf , mclr to 5V.
Thanks
I am trying to send chars to pic16876a using max232N (texas).
The simulation with proteus works just fine but with real circuit I am
facing with some strange beaviors. I have the following connections:
DB9 Connector <-> MAX232N
2 -> 14
3 -> 13
5-> gnd 15
max232n - PIc16876A
11 -> 17
12 -> 18
By using Terminal software I can see that max232 and cable are working. Infact
if I stick 11 and 12 togheter on max232 I got the
echo string in Terminal.
The firmare in pic is a simple Hitec C program which should give
me back data, here it is:
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 #include <stdio.h> #include <htc.h> #include "usart.h" #include <stdlib.h> #ifndef _XTAL_FREQ #define _XTAL_FREQ 10000000 #endif void putch(unsigned char byte) { while(!TXIF) //wait until TXIF is high continue; TXREG = byte; //put byte into Transmit Register TXIF = 0; } unsigned char getch() {/* retrieve one byte */ while(!RCIF) /* set when register is not empty */ continue; RCIF = 0; return RCREG; } unsigned char getche(void) { unsigned char c; putch(c = getch()); return c; } void init_enable() { BRGH = 1; /* high baud rate */ SYNC = 0; /* asynchronous */ SPEN = 1; /* enable serial port pins */ CREN = 1; /* enable reception */ SREN = 0; /* no effect */ TXIE = 0; /* disable tx interrupts */ RCIE = 0; /* disable rx interrupts */ TX9 = 0; /* 8- or 9-bit transmission */ RX9 = 0; /* 8- or 9-bit reception */ TXEN = 1; /* enable the transmitter */ RCIE =1; PEIE =1; } void main(void){ //printf("TEST - 12/12/2013", '\n'); char rxbyte; TRISB = 0; PORTB = 0; INTCON=0; INIT_COMMS(); // set up the USART - settings defined in usart.h init_enable(); // just blinking a led int a; a = 0; while(a < 5) { PORTB=0xFF; __delay_ms(300); PORTB=0x00; __delay_ms(300); a = a +1 ; } printf("********* WELCOME ***********", '\n'); while(1){ rxbyte= getche(); unsigned char input; switch(rxbyte) { case '1': { PORTB=0xFF; printf("led on", '\n'); putch('\n'); } break; case '2': { PORTB=0x00; printf("led off", '\n'); putch('\n'); } break; case '4': { int i; for(i=0;i!=100; i++) { putch('a'); <- when i send 4 i don't get it back. But with PRoteus and PIMCOM works! } } default : break; } } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 #ifndef _SERIAL_H_ #define _SERIAL_H_ #define BAUD 9600 #define FOSC 10000000L #define NINE 0 /* Use 9bit communication? FALSE=8bit */ #define DIVIDER ((int)(FOSC/(16UL * BAUD) -1)) #define HIGH_SPEED 1 #if NINE == 1 #define NINE_BITS 0x40 #else #define NINE_BITS 0 #endif #if HIGH_SPEED == 1 #define SPEED 0x4 #else #define SPEED 0 #endif #define RX_PIN TRISC7 #define TX_PIN TRISC6 /* Serial initialization */ #define INIT_COMMS()\ RX_PIN = 1;\ TX_PIN = 1;\ SPBRG = DIVIDER;\ RCSTA = (NINE_BITS|0x90);\ TXSTA = (SPEED|NINE_BITS|0x20) void putch(unsigned char); unsigned char getch(void); unsigned char getche(void); #endif
The rs232 parameters are the same. What's wrong?
When i power on the pic I should get the led blinking on port b, but it doesn't. Components are 10Mhz 22pf , mclr to 5V.
Thanks