PDA

View Full Version : Serial Input for the 8051


James
10-17-01, 02:05 PM
I am trying to write a serial input routine for the NMIY-031 board that uses the 8051 MCU and the MAX232 serial I/O chip.

I am trying to talk to the chip using MAXTERM at 9600 baud. Using the same 8/N/1 format that is used by the Monitor V1.1 program.

My routine will only catch an occassional character and I can't figure out how to get it to catch each keystroke dependably. Any help would be greatly appreciated.

Here is the code that I am using:





; serial INPUT routine for the 8051 (doesn't work dependably)

; start program
.ORG 8000H
;Monitor send character routine
.EQU PUTC, 0114h
;Set baud Constant for 9600 baud
;Using a 11.0592 MHz crystal
.EQU Baudnum, 0FDh
;set SMOD bit 0 for Baud x 32 rate
ANL PCON,#7Fh
;clear timer T1 configuration only
ANL TMOD,#0h
;set timer T1 as an 8-bit autoload
ORL TMOD,#20h
;set TL to roll over on next cycle
MOV TL1,#0FFh
;TH1 set Baudnum of 0FDh for 9600 baud
MOV TH1,#Baudnum
;set Timer 1 to run
SETB TR1
;set SCON for UART mode 1
MOV SCON,#7Ch
;Prepare to receive
SETB REN

;The following polling loop only catches a
;keyboard character once in a while
;When it does catch a character it
;prints the correct character
;so it seems to be working half-way right
;But why doesn't it catch EVERY character???


;just a loop lable
LOOP: NOP
;Loop here until Char received
GETCHAR: JB RI, RECEIVE
SJMP GETCHAR

;Get the Charcter
RECEIVE: MOV A,SBUF
;Clear the RI bit CLR RI
;Print the Character using a call to the Monitor
LCALL PUTC


;The following code allows me to
;return control to the monitor by typing a period
;This part of the program works just fine. :o)


;copy the character into B
MOV B,A
;Clear the Carry flag
CLR C
;Load A with the period (2Eh)
MOV A,#2Eh
;TEST FOR PERIOD
SUBB A,B
;Return to the Monitor if a period is detected
JZ FINISH
;Otherwise Stay in the program for another input
SJMP LOOP

;back to monitor prompt
FINISH: LJMP 05AH ;
.END



Any help would be appreciated.
If you have a workable character input routine maybe you could just send me the .asm file for that?

Also if anyone has an assembly listing for the Monitor V1.1 program I would also appreciate that.

And finally, I could use an 8051 disassembler

Thanks,
James

nmitech
10-17-01, 04:42 PM
James,

The 8051MON.DOC provided in the disketted has the SERIAL, putchar, and puts drivers of the Monitor. If you do not have this file please email me at nmitech@newmicros.com

Due to the NMI's policy, i can not release any source code to customers. I am sorry for the inconvinience.

nmitech
----------

James
10-17-01, 04:58 PM
I found the solution to my own problem.

Because my program has been launched by the Monitor, and becuase my program was calling the Monitor for the putchar routine, I needed to disable the Global interrupts during my polling routine. That's what was causing the problem. The program works perfectly now.

This line need to be executed just before the getchar routine,...

;DISABLE GLOBAL INTERRUPTS
ANL IE,#6Fh

;Loop here until Char received
GETCHAR: JB RI, RECEIVE
; Wait Again for Character
SJMP GETCHAR


Thanks anyway. :o)






;Disregard the following, I have solved the problem.
Hi,

Yes I have the 8051MON.DOC provided in the disketted, and it has the SERIAL, putchar, and puts drivers of the Monitor.

But there is no documentatoin for getting a character INTO the program. I can write routines to print characters out to MAXTERM with no problem. I just call putchar at 0114h of the Monitor.

But how do I get my program to read a character from the serial port so that I can talk to my program using MAXTERM?

The Monitor doesn't have a "getchar" routine in the documentaion. Obviously the Monitor itself must have a getchar routine since I can give the Monitor commands using MAXTERM.

All I want to do is be able to input characters into my programs in the NMIY-31 RAM using MAXTERM. I need to be able to READ characters from the serial port.


Thanks,
James

Bruce Juntti
11-01-01, 06:59 PM
I am still in exactly the same predicament, James. The
serial-in routine is not documented in the 8051MON.DOC
file. Being new to 8051 assembly, I'm not having a lot
of luck getting characters into my program from
the monitor. I've built a breadboard incorporating the NMI-0031 board and I'm experimenting with Dallas 1-wire code and I sure would like some input on this issue. Some time ago I posted a similar plea and
never really got a revelant answer. Can you help, nmitech?

Also, if anybody else out there is doing Dallas 8051 code and would care to share notes/code that would be great!

James
11-01-01, 08:00 PM
Hi Bruce,

I'm afraid that I really don't know much about using Dallas 1-wire micro-networking. I am basically just using the standard 2-wire serial port to communicate to the 8051 via a program on my PC.

My goal is to replace the machine languge Monitor V1.1 that comes on the NMI board with my own serial communications program. My 8051 program will be taylored to communicate with a program on my PC that is written in C++.

I'm bascially already there as far as the technical details are concerned. But I have a long way to go with the C++ program to build up a user-friendly GUI. I probably should have done this with Visual Basic.

In any case, once I turned off the Interrupts I was home free. Evidently the Monitor V1.1 sets up interrupt vectors during boot-up that cause program execution to jump back to the Monitor ROM when the serial port activates an interrupt. The other way to solve this problem would be to simply change the interrupt vectors to point to my own serial routine. I'll probably do that later. Right now I am using a simple Polling routine that doesn't require interrupts. So I just disable the interrupts. I don't imagine that would work too well in a mirco-newtworking environment.

In any case, I also have the "Green Book" which comes in real handy. Title: The 8051 Microcontroller Architecture, Programming, & Applications. By Kenneth J. Ayala. ISBN number 0-314-20188-2

This book is fantastic for anyone programming the 8051. I'm sure it would come in handy. Although there is nothing in the book about Dallas 1-wire networking.

I just typed "Dallas 1-wire 8051" into a search engine and came up with a whole bunch of interesting URLs. That's about all I would know to do at this point.

James