??? 08/09/04 10:31 Read: times |
#75659 - RE: RS232 - PC&51 communication Responding to: ???'s previous message |
As Raghu explains - check out the ascii table. The 8051 has no problem with ascii chars.... mov a,SBUF cjne a,#':',not_colon ;most assemblers accept this Lets say we have a table of 8 bytes, each with the value from the a/d and we want to send them out the 8051 serial port to the PC: atod_values: ds 8 ;in internal ram mov a,#':' ;start token call pchar ;sends A out the serial port mov r5,#0 ;clear checksum mov r0,#atod_values ;->data to send mov r2,#8 ;loop count - 8 bytes of data loop: mov a,@r0 ;get data push a add a,r5 mov r5,a ;accumulate the checksum pop a call phex ;convert to ascii hex & send inc r0 ;->++ djnz r2,loop mov a,r5 com a ;negate the checksum call phex mov a,#13 ;add carriage return call pchar mov a,#10 ;add line feed call pchar ; end of send code... ; ; converts value in A to ascii hex and sends ; phex: push a swap a ;get hi nibble call tohex pop a call tohex ret tohex: anl a,#0fh ;low 4 bits only add a,#'0' ;add ascii offset for 0...9 cjne a,#'9'+1,tohex_1 tohex_1 jc tohex_2 add a,#7 ;for A..F tohex_2 call pchar ret pchar: jnb TI,pchar mov SBUF,a clr TI ret See, I've done half the work for you! The visual basic side you can do for yourself - besides I haven't used VB for some time! You're in the right area when talking about ON_COMM events. Use 'lineinput' to grab the text line (VB looks for the CR or LF to figure out the end of the message). Use the VB string features to pull apart the receive string and convert back to data to process and/or display. Job done. First, get the 8051 code going and use Hyperterm to check that the data is being sent correctly - then use VB. You can choose whether or not to check the checksum value - get the basics going then add the checksum calc to your VB code to check that the data was received correctly. p.s I wrote this code off the top of my head - don't expect it to be 100% although it should be close! |
Topic | Author | Date |
RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
Not modem | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
Using VB6.0 OnComm | 01/01/70 00:00 | |
RE: Using VB6.0 OnComm | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication![]() | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 | |
RS232 - VB&51 data transfer | 01/01/70 00:00 | |
RE: RS232 - PC&51 communication | 01/01/70 00:00 |