Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to receive numbers from Keil C51 to PIC16F628 in CCS?

Status
Not open for further replies.

GrandAlf

Advanced Member level 2
Joined
Mar 9, 2002
Messages
520
Helped
47
Reputation
92
Reaction score
6
Trophy points
1,298
Location
UK
Activity points
4,730
I am wanting to send numbers 0-255 from k*e*il c51 to PIC16F628 programmed with CC*S C. It seems that I can send them with printf %U, but I am not sure about how to receive them. If I use any of the built in commands, such as getc, it appears to interpret them as characters rather than numbers. Supposing I send 13, it would be interpreted as CR by getc rather than 13. which is what I require. I just need to to receive the number, but not echo it. Any advice appreciated.
 

how to enable serial port ccs

Check out the CCS forum at:

https://www.ccsinfo.com/forum

You will get a lot of ideas just browsing their forum ...

The guys there are nearly as nice as the members here :)

best regards
 

ccs getc

Thanks C-Man,

Got some useful stuff there. Another question if I may, Anyone know how to use the serial port on Atmel 89S8252 with K*eil C51. I know it is referred to as TXD in the header file. Dont seem to be able to find info on setting baud rates etc. Xtal is 12mhz, and I need to sed the baud rate to 300. Also I assume that when using printf %u, I need to specify the stream as TXD ?. Sill learnig C, any help appreciated.

PS, Only need to transmit without handshaking.
 

ccs serial getch

Just another thought. As I only want to output a single 8 bit number at any one time, can I just use the statement SBUF = oxxx;. I guess I need to set up the timers for the baud rate, not sure how to work it out. Also I am using tiny RTOS, will this cause serial probs?. Sorry! lots of questions.
 

getch vs getc ccs

This is a short snippet out of one of my C51 programs to initialize communication:

/* RS232 Init at 19200 Baud (using Timer1) */
TH1=0xFD; /* 19200 baud @ 11.0592MHz*/
TL1=0xFD;
SCON=0x50; /* 01011010b: UART Mode1, enable receiver */
PCON=SMOD_; /* double baudrate '/
TR1=1; /* start timer 1*/
ES=1; /* Serial Interrupt on */

If you use interrupt driven RS232 there should not be a problem with RTOS but I have not used RTOS so I can not tell you for sure ...

hope this helps
 

ccs baudrate

This is great C-Man, How do you work out the baud rate values?, need to use 300 with 12mhz xtal (system clock 1Mhz). Going to try and download atmel data sheet to see if I can find the info, don't expect you to do all the work!. BTW, can you use SBUF like above, seems to compile OK, but unable to test as yet.
 

ccs serial interrupt

Maybe Mr. Keil can help you :)

hxxp://www.keil.com/c51/baudrate.asp

And yes just use SBUF to get/put from/to 8051 USART but you have to check the USART flags if you are allowed to get/put a new byte from/to USART.

I am afraid the title of this topic is a little off now ...

best regards
 

ccs c getc()

Is getting rather off topic I think, anyway managed to find the solution.

void serial_init (void) {
SCON = 0x50; // mode 1: 8-bit UART, enable receiver
TMOD |= 0x20; // timer 1 mode 2: 8-Bit reload
TH1 = 0x98; // reload value 300 baud
TR1 = 1; // timer 1 run
ES = 1; // enable serial port interrupt
}

thanks for your advice
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top