1.) Title Page

Example of a typical laboratory report. RS232 soft UART

PART 1

Statement of Problem

Design a RS232 Universal Asynchronous Receive Transmit in software using the Motorola 68HC11E micro-controller. The hardware consists of two HC11 devices, both capable of receiving and transmitting characters. One deviation in the design has been incorporated in order to ease the implementation. Instead of using the –3 to –12 volts to implement the mark state only the TTL logic high (2.4 to 5.0) is used. Likewise, +3 to +12 the space, is represented by the TTL logic low (0.0 0.5).

One of the two controllers uses the built-in Port A for the serial data input and output. Serial data in is implemented with data bit 0. Serial output data is implemented with data bit 4 of Port A. The other HC11 controller uses hardware ports at memory location $5b84 bit 0 for serial input data and memory location $5b86 bit 0 for serial output data.

The student is to design the external ports for the HC11, and commit the design to hardware. Software is written to implement the serial transmission and receiving of the data for both controllers.

Both controllers are interfaced to a PC that generates and downloads object code using the BUFFALO monitor. These same controllers can use the existing RS232 hardware interface to provide both the source of data to be transmitted over the TTL link, and provide a terminal to display data received over the TTL link. To this end, the BUFFALO monitor provides two subprograms. The first, outadisplays the character in accumulator a. The second, inchar acquires the ASCII value of the key pressed for transmission over the soft UART link.

PART 2

Hardware Design

Part A

Basic Controller is the AXIDE HC11. Port A is a dedicated output port at memory location $1024. The 68HC11E specify the following attributes for that port. Bits 0,1 and 2 are dedicated input. Bits 4,5 and 6 are dedicated output. Bits 3 and 7 are bi-directional and will not be used in this application. The pins from this port are attached to a standard 5 pin DIN plug. A crossover is provided such that the output from port A is connected to the input of the second controller. Likewise, the output from the second controller is connected to the input. Bit 0 of Port A is used for input, and bit 4 of Port A is used for output.

Diagram 1 shows the connection of the port to the DIN plug.
Pin 1 Not used

Pin 2 Serial in/Serial out (crossover)

Pin 3 Serial out/Serial in (crossover

Pin 4 Ground

Pin 5 Not used

Part B

The design of the second controller is not as straight forward. The AXIDE has partial decoding provided by Chip Select C0 through C7. The manual provided by AXIDE shows the breakdown of these chip selects. Each chip select provides for 16 possible ports, determined by addresses A0 through A3. The chip selects start at $b580 and end at $b5FF. CS0 is used in this design and it is already conditioned with the E signal so that it will not need to be incorporated in the decoder. All chip selects are active low.

The input Port uses a 74LS244 tri-state buffer. Bit 0 is aligned with D0, and only one of the eight is used. A pull-up resistor is used so that a mark is present if there is no connection between the two units. The decoding logic uses the CS0 and addresses A0, A1, A2, and A3. CS0 address $b580 through $b58f. A3, A1 and A0 are low and address A2 is high. A 5 or 6 (depend if read or write) input AND gate is required, so the 8 input AND gate could be used tying the remaining three inputs high. The diagram using the 8 input AND is shown but was not used in the application.

However, I choose to use the 74ls138 (1 of 8 decoder) because only single TTL device provides both input and output decoding.

The output or write must be conditioned with the /WR signal. It is the E that actually latches the data, but the /WR must be used to enable the write process. The 74ls374 is used to latch the data from the controller; only bit 0 (D0) is used. The other seven are available for other applications. The completed design is shown in circuit diagram.

PART 3

Software Design

Flow Charts

Flow Charts for both transmit and receive are shown. These are the basic subroutines used in this application. To provide full duplex operation, data source is the PC keyboard and the received data is displayed on the PC monitor. Data from the keyboard is in ASCII format with 7 bits for the code, and one bit that could be used for parity, but in this example it is always 0, indicating no parity. The ASCII data from keyboard is available in the A accumulator must be converted into serial format. The protocol for the serialization of this data is in asynchronous format. The communication link is established by raising the output serial bit high. This is the mark state. When a byte of ASCII data is to be transmitted in serial format, the mark is lowered to the space or logic low. The rate at which the data is to be sent (baud rate) determines how long this space condition holds. Data is transmitted starting with the least significant bit progressing to the most significant bit. This followed by the parity, which in this case is always a space. The sequence is terminated with two stop bits or marks

Indicating the end of a byte transmission. The sequence is repeated each time that a key is depressed. This is the asynchronous behavior of the transmission. Once the start bit commences the following bits follow in a synchronous sequence of marks and spaces that form the eight bits of the transmitted character. The sequence terminates with the transmission of two marks forming the stop bits.


PART 4

Software Design

Code Transmit and Receive

* Program to software emulate RS232C communication

* Transmit program

* PortA $1000 bit 4 is serial data out.

*Use DIN plug that connects to keyboard

***************

* EQUATES *

***************

***************

* EQUATES *

***************

outa EQU $ffb8

outcrlf EQU $ffc4

outstring EQU $ffca

inchar EQU $ffcd

eot EQU $04 end of text/table

RS232C equ $ 1000

rsout equ $1000 Port A bit 4 for output - must convert to RS232

tin equ $1000 Bit 0 for input RS232 data_in

clk equ $80

data equ $01 data bit 0 has mark or space data

msb equ $80

buf_length equ %11011111 wrap around total 32 bytes

* data pin 1, clock from keyboard pin 8

*clk equ $80

*data equ $01

***********************

* Program starts here *

***********************

* ORG $8000 if RAM installed in U6

ORG $1040 RAM starts in U5 $1040 and ends at $7FFF

START

lds #$200 start of Stack Pointer

ldaa #$10 00010000 bits 0,1,2 are input, bit 3,7 bi-directional bits 4,5,6 out

staa rsout place line in MARK state

ldx #rsout another way, if we reserve x it could save some code

bclr 0,x,$10 TEST PURPOSE clear then rset, can not use indirect,

;only direct and register

bset 0,x,$10 this should also do it

ldx #MSG get message string

JSR outstring send it out PC Monitor

wait1

jsr outcrlf

jsr inchar Get character from PC, loop until character is received

staa character store the character received

jsr outa echo on PC

ldaa character get it back

bsr TTout echo on RS232 terminal

bra wait1 wait for next character

*Subroutine to output character

TTout

pshx

tab save copy in B

ldx #rsout disp has latch on bit 4

bclr 0,X,$10 only bit 4

;Note AS11 does not want comma, where ASM11

; bclr 0,X,01. AS11 will encode for the mask in all

;cases a $00, and NO! error warning

bsr delay send start bit

ldaa #8 start plus 8 data bits

staa count

tba get data

next

rora if carry high send mark

bcc space

bset 0,X,$10 send mark

bra done

space bclr 0,X,$10 send space

done bsr delay wait

dec count all eight sent?

bne next

bset 0,X,$10 send stop frame

bsr delay

pulx

rts

* time delay subroutine for 1200 bits/second

delay

psha

ldaa #38

delay1

deca

bne delay1

pula

rts

* Half delay for Receive program

half_del

psha

ldaa #38/2

delay2

deca

bne delay2

pula

rts

* time delay subroutine for 1200 bits/second

long_d

psha

pshx

ldx #0

ldaa #$10

delayd

dex

bne delayd

deca

bne delayd

pulx

pula

rts

MSG FCC 'A RS232C Example.'

FCB $0a

FCC 'Program sends character from PC to dumb terminal'

FCB $0a Line feed had automatic cr.

FCC 'JPF'

FCB EOT

count RMB 1

character RMB 1

**********

* org $fffe reset vector

* fdb START

* Program to software emulate RS232C communication

* Receive

*Use DIN plug that connects to keyboard

***************

* EQUATES *

***************

***************

* EQUATES *

***************

outa EQU $ffb8

outcrlf EQU $ffc4

outstring EQU $ffca

inchar EQU $ffcd

eot EQU $04 end of text/table

rsout equ $b586 16v8 bit 0 pin 14 (Q0) for output - must convert to RS232

tin equ $b584 RS232 data_in 74244 bit 0

clk equ $80

data equ $01 data bit 0 has mark or space data

msb equ $80

***********************

* Program starts here *

***********************

* ORG $8000 if RAM installed in U6

ORG $1040 RAM startsin U5 $1040 and ends at $7FFF

START

lds #$200 start of Stack Pointer

ldaa #01

staa rsout place line in MARK state

ldx #rsout another way, if we reserve x it could save some code

bclr 0,x,01 TEST PURPOSE clear then rset, can not use indirect,

;only direct and register

bset 0,x,01 this should also do it

ldx #MSG get message string

JSR outstring send it out PC Monitor

wait1

jsr outcrlf

bsr TTin get character from RS232

jsr outa display on PC Monitor

bra wait1 wait for next character

* Subroutine TTYIN

TTin

pshx save x pointer to stack

ldx #tin

check ;Note difference between ASM11 and AS11

;in the instruction that follows

;ASM11 brset 0,X,data,check

;AS 11 gives no warning of syntx error

;just message branch out of range

;however it is OK - Not so with bset and bclear

;here the mask byte always codes as $00

;major error if your eyes don't pick it up!

;see below

brset 0,X,data,check ;if high, in mark state, wait for low

bsr half_del wait to mid period

bsr delay middle of first bit

*get character

ldaa #8 number bits required

staa count memory location to count bits received

ldy #character pointer to mapped location of the to be stored scan character

rec_data

ldaa 0,x get data in lsb

rora shift to carry

ror 0,y shift carry into character

bsr delay

dec count

bne rec_data

* All 8 bits receieve

**** ldaa 0,y !to see it on breakpoint

bsr half_del end of first stop bit

bsr delay

ldaa character get character from memory

pulx restore stack

rts return with scan code

*Subroutine to output character NOT USED IN THIS EXAMPLE!

TTout

pshx

tab save copy in B

ldx #rsout disp has latch on bit 4

bclr 0,X,$10 only bit 4

;Note AS11 does not want comma, where ASM11

; bclr 0,X,01. AS11 will encode for the mask in all

;cases a $00, and NO! error warning

bsr delay send start bit

ldaa #8 start plus 8 data bits

staa count

tba get data

next

rora if carry high send mark

bcc space

bset 0,X,$10 send mark

bra done

space bclr 0,X,$10 send space

done bsr delay wait

dec count all eight sent?

bne next

bset 0,X,$10 send stop frame

bsr delay

pulx

rts

* time delay subroutine for 1200 bits/second

delay

psha

ldaa #38

delay1

deca

bne delay1

pula

rts

* Half delay for Receive program

half_del

psha

ldaa #38/2

delay2

deca

bne delay2

pula

rts

MSG FCC 'A RS232C Example.'

FCB $0a

FCC 'Program sends character from PC to dumb terminal'

FCB $0a Line feed had automatic cr.

FCC 'JPF'

FCB EOT

count RMB 1

character RMB 1

**********

* org $fffe reset vector

* fdb START

PART 5

Software Design

Flow Chart Full Duplex

PART 6

Software Design

Code Full Duplex

* Filename RS_rec3.asm Appears to work!

* Duplex Model

* Program to software emulate transmit and receive data using RS232C protocal communication

*

* This board used additional hardware to receive the serial data in memory location $b584

* It also has hardware at $b586 bit 0 for serial output

* The received data is sent to PC monitor using HC11 internal RS232, but it also displays

* the data on a display added to board last semester

*Use DIN plug that connects to keyboard. A crossover is incorporated after DIN Plug

*so that a crossover cable did not have to be constructed.

***************

* EQUATES *

***************

* BUFFALO MONITOR ROUTINES USED IN PROGRAM

outa EQU $ffb8

outcrlf EQU $ffc4

outstring EQU $ffca

inchar EQU $ffcd

eot EQU $04 end of text/table

* Input and Output memory Maps, with constants used for masking

rsout equ $b586 16v8 bit 0 pin 14 (Q0) for output - must convert to RS232

tin equ $b584 RS232 data_in 74244 bit 0

display equ $b580 Litronx LED display on HC11 board

scsr equ $102e ;serial com status register

; bit 5 receive data register full if 1

rdrf equ $20 ;test to see if key data is availaible

data equ $01 data bit 0 has mark or space data

msb equ $80

***********************

* Program starts here *

***********************

* ORG $8000 if RAM installed in U6

ORG $1040 RAM startsin U5 $1040 and ends at $7FFF

START

lds #$200 start of Stack Pointer

ldaa #01

staa rsout place line in MARK state

ldx #rsout another way

bset 0,x,01 this should also do it

ldx #MSG get message string

jsr outstring send it out PC Monitor

jsr outcrlf

* This section of code alternates between to possible inputs. One from the PC requesting that

* a character be transmitted. The other checks the status of the software UART to see if a character

* is waitng to be received. If so, it collects character, displays on led and sends to PC Monitor.

wait1

;scan for request to send from PC using HC11 RS232

check_PC

ldx #scsr ;on the fly test to see if character awaits from PC

brset 0,x,rdrf,getit ;if high a character availible

bra check_receive ;is one is availible on soft rs232

getit

jsr inchar ;if so get it from keyboard

bsr TTout ;and send it

check_receive

ldx #tin check status of mark input, if high no data to input

brset 0,x,data,check_PC ;if high (mark) no character, low get character

bsr TTin get character from software RS232

jsr outa send via RS232 to on PC Monitor

staa display display on led on HC11 board

bra wait1 wait for next character

* Subroutine TTYIN

TTin

pshx save x pointer to stack

ldx #tin

check ;Note difference between ASM11 and AS11

;in the instruction that follows

;ASM11 brset 0,X,data,check

;AS 11 gives no warning of syntx error

;just message branch out of range

;however it is OK - Not so with bset and bclear

;here the mask byte always codes as $00

;major error if your eyes don't pick it up!

;see below

* No need to check brset 0,X,data,check ;if high, in mark state, wait for low

bsr half_del wait to mid period

bsr delay middle of first bit

*get character

ldaa #8 number bits required

staa count memory location to count bits received

ldy #character pointer to mapped location of the to be stored scan character

rec_data

ldaa 0,x get data in lsb

rora shift to carry

ror 0,y shift carry into character

bsr delay

dec count

bne rec_data

* All 8 bits receieve

**** ldaa 0,y !to see it on breakpoint

bsr half_del end of first stop bit

bsr delay

ldaa character get character from memory

pulx restore stack

rts return with scan code

*Subroutine to output character. Once entered, character in a register is sent

TTout

pshx

tab save copy of character in B register

ldx #rsout memory addres to latche bit 0

bclr 0,x,data only bit 0 used for datat transmission

;Note AS11 does not want comma, where ASM11

; bclr 0,X,01. AS11 will encode for the mask in all

;cases a $00, and NO! error warning

bsr delay send start bit

ldaa #8 start plus 8 data bits

staa count

tba get data

next

rora if carry high send mark

bcc space

bset 0,x,data send mark

bra done

space bclr 0,x,data send space

done bsr delay wait

dec count all eight sent?

bne next

bset 0,x,data send stop frame

bsr delay

pulx

rts

* time delay subroutine for 1200 bits/second

delay

psha

ldaa #38

delay1

deca

bne delay1

pula

rts

* Half delay for Receive program

half_del

psha

ldaa #38/2

delay2

deca

bne delay2

pula

rts

* Sign on message.

MSG FCC 'A RS232C Example.'

FCB $0a Line feed has automatic return.

FCC 'Program receives character from HC11 and dispalys on board and PC Monitor'

FCB $0a

FCC 'JPF'

FCB EOT

count RMB 1

character RMB 1

**********

* org $fffe reset vector

* fdb START

* Filename RS-send1.asm Should have corrections and work duplex

* Program to software emulate RS232C communication

* Transmit and Receive program Uses built-in Port A on HC11E9 3inputs,3outputs,2 bidirectional

* PortA $1000 bit 4 is serial data out.

* PortA $1000 bit 0 is serial data in.

*Use DIN plug that connects to keyboard This board has crossover wired.

***************

* EQUATES *

***************

outa EQU $ffb8

outcrlf EQU $ffc4

outstring EQU $ffca

inchar EQU $ffcd

eot EQU $04 end of text/table

RS232C equ $ 1000

rsout equ $1000 Port A bit 4 for output - must convert to RS232

tin equ $1000 Bit 0 for input RS232 data_in

display equ $b580

clk equ $80

data equ $01 data bit 0 has mark or space data

outbit equ $10

scsr equ $102e ;serial com status register

; bit 5 receive data register full if 1

rdrf equ $20 ;test to see if key data is availaible

***********************

* Program starts here *

***********************

* ORG $8000 if RAM installed in U6

ORG $1040 RAM startsin U5 $1040 and ends at $7FFF