Networked Home Theater

Final Paper

By

Jeff Patrick

Advisor: Alexander Malinowski

Abstract:

The scope of the Networked Home Theater project is to develop an interface to connect a Sony CD player to a home Intranet. The project consists of hardware and software components. The hardware part consists of a microprocessor that controls communications between the CD player and the host PC. The software part consists of three separate programs, firmware code that is executed by the microprocessor in the hardware interface, a server that interfaces the microprocessor to the applets, and a user interface in the form of an applet. The firmware code is written in 8051 Assembly language, and the server/applet combination is written in Java.

The server communicates with the microprocessor and the applet to moderate communications. A chat function is implemented in the server software to enable multiple users to communicate among themselves.

The applet is the front end of the project, and is what the end user interacts with. The applet displays status pertaining to the current CD and controls for the CD player. The firmware code is in charge of translating codes between the CD player and the host PC.

Introduction

Most Sony home theater components have a built in communications bus and proprietary protocol. The various components connect to each other through a S-Link port. S-Link is a two-wire proprietary serial data bus that provides two way communications. Sony’s intent for this bus is to allow their components to interact and allow an easier and more fun home theater experience.

The Networked Home Theaters’ firmware code and microprocessor hardware connects the S-Link bus to a PC (Personal Computer). The PC gives an opportunity for advanced automation of the components. The PC is able to control the CD player as well as read information from it. A server on the PC will allow applets to connect remotely via the Internet and control the Sony components.

Figure 1. The block diagram of the Networked Home connected to the home Intranet or to the Internet.

Figure 1 shows the block diagram of the entire system. The Sony component connects directly to a microcontroller through the S-Link connection. The microcontroller provides communication between the Sony components and the host PC.

The microcontroller is connected to a PC running a control server. The connection is made through an RS-232 serial port. The microcontroller and PC communicate to each other by using a UART. The UART controls low level communications and makes talking between systems simpler.

The server manages several tasks.

Modes of Operation:

Idle

The system is in an idle state while it is waiting for a client to connect to the server and control the unit (Remote Control Mode) and listens to activity on the S-Link bus. In the case of playing a new CD, the mode switches to Query mode.

Remote Control

A remote user is controlling the system. The user sends input through the system, and the system sends back status information to the user. When a user plays a CD the system temporarily switches to the Query mode so that the CD information may be retrieved. The current command set is listed in Table 1 below:

Play: Will play the selected Disc and track.

Stop: Will stop all activities of the CD player.

Pause: Will toggle pause mode while in play mode.

Next Track: Switch to the next track on the disc.

Previous Track: Switch to the previous track on the disc.

Power: Will toggle the CD player power if digitally controlled.

Disc Check: Will report status on all of the discs in the player. (Not Implemented)

Eject: Eject the CD tray.

Next Disc: Switch to the next disc.

Previous Disc: Switch to the previous disc.

Disc<Disc #> Switch to the first song of <Disc #>. (Not Implemented)

Disc<Disc #><Track #> Switch to song <Track #> on disc <Disc #> (Not Implemented)

Track<Track #> Switch to track <Track #> on the current disc. (Not Implemented)

Fade<Seconds> Fade the music to zero volume over <Seconds> seconds.

Ramp<Seconds> Ramp the music up to full volume over <Seconds> seconds.

Send: Sends the text currently in the chat text field.

Connect/Disconnect: Connects or disconnects the user from the Networked Home Theater server. A unique username is required to connect to the server.

Fast Forward: Plays the disc in fast forward.

Fast Fast Forward: Plays the disc in double fast forward.

Back: Plays the disc in rewind.

Fast Back: Plays the disc in fast rewind.

Table 1. Current instructions to be made available to a remote user of the system.

Query Mode

The CD player reports the track length of the current song. By obtaining the length of each track on the disc, the disc can be identified and information can be retrieved from the CDDB database. After obtaining the information the system returns to the mode previously active.

Inputs/Outputs:

CD Player

Port: S-Link 1 The CD player sends status information to the microcontroller. It also receives instructions from the microcontroller on the same port.

Port: S-Link 2 May be used to connect multiple Sony components to the Networked Home Theater

Port: RCA Out The CD player sends analog music signals out from the RCA ports. The music signals will be sent to an unspecified receiver to be processed.

Port: Digital out This is the raw digital music read from the CD. This port is not used.

Microcontroller

Port: RS232 This port is connected to the PC to send status signals and receive instruction signals.

Port: S-Link This port is connected to the S-Link bus to control the CD player and receive status information.

PC

Port: RS-232 Serial This port is connected to the microcontroller to send and receive instructions or status information.

CDDB SDK: The proprietary SDK from CDDB.com will be used to connect to the CDDB database and obtain information about the CD contents. Not Implemented.

TCP/IP Socket A TCP/IP socket is used to connect to the client applet and send/receive control information and CD information.

Applet

TCP/IP Socket The TCP/IP port is used to connect to the server and obtain information about the CD as well as send/receive chat information. It is also used to send the user input back to the server.

GUI The GUI (Graphical User Interface) is the front end of the project. It displays pertinent information about the CD playing as well as chat information from other connected users.

The Hardware Interface

In order to connect the CD player to the PC, several factors have been taken into consideration. The CD player outputs TTL (0-5) voltages, while the serial port on the PC outputs RS-232 (+-15V) voltages. Some voltage conversion must be done in order to connect the two.

Second, the CD player communicates at a 600-microsecond time base. The server, which is written in Java, inherently has a minimum wait time of 1 millisecond. In order to communicate at the speed required, the communications functions must be written in a separate language. In addition, if the S-Link signal is read directly by the host PC, the host PC will be slowed down considerably by the need to monitor a port at high speeds. This is a very large waste of processor power since the S-Link bus is unused 99% of the time.

To reduce strain on the host PC system, and reduce the complexity of the server software, a microprocessor will interface the PC to the CD player. The microprocessor has the ability to communicate to the CD player at a 600 microsecond base frequency. It can then talk to the PC at a slower speed. The microprocessor will also take care of the voltage conversions between TTL and RS232. Figure 1 shows the block diagram of the entire system with the microprocessor interface. In addition to controlling just Sony devices, the microprocessor has the capability to talk to different bus’s if the need arises.

Figure 2. Microprocessor Code Flowchart

Firmware Code

Figure 2 shows the entire microprocessor code flowchart. The processor is in the idle state for the majority of the time. While in the idle state it will listen to both the Serial and the S-Link bus. When information is detected on either bus, it will convert the information into the opposite format and send it. If the ability to interface multiple buses is implemented, the microprocessor will need to analyze the incoming signal and route it accordingly.

Figure 3. Server Code Flow Chart

Server Code

The server has several functions, which are shown in figure 3. The first operation of the server is to wait for a connection from an applet. Once a client is connected, the server transmits status information about the system. After the status information is sent the server waits for an instruction from the client. When an instruction is received, the server pass’ the command to the microprocessor through the Serial Port Out. Finally, the server returns to the Wait for Instruction mode.

The server is also running a separate thread to detect if any information is being sent from the microprocessor. When status information is received from the microcontroller, the server analyzes the data. In a future version of the project, the data may be CD identification information. If so, the server will connect to CDDB using proprietary libraries from Gracenote/CDDB. If the data is not a CD identification number, the server will skip the CDDB connection step. The code then enters a Report Status block. This block parses the data received from the microcontroller or from CDDB.com and prepares it for display. Finally, the data to be displayed will be sent to an applet through the Socket Out block.

Figure 4. Chat Server Block Diagram.

A second service is running within the control server to manage the chat functions. Figure 4 shows the server flowchart when a user connects. First the user connects to the server. Next, the server will wait for new data to be transmitted. When a user sends chat data from the applet, the data is received in the wait block of figure 4. The data is then broadcast to all connected users.

Figure 5. Applet Code Block Diagram

Applet Code

Figure 5 shows the flowchart for the Applet. The applet will connect to the server and split into two threads. The thread on the left waits for data to be sent from the server. When the applet receives data (either chat or status data) it will display it on the GUI of the applet. The thread on the right waits for data to be input by the user. Once the user sends a command or chat data the applet sends the data to the server. The server will then send a reply to the applet with either the chat info or updated status on the CD player.

Figure 6. Applet GUI

The picture in Figure 6 is the applet front end. The center of the applet is the chat history. The applet displays the status of the system near the top of the GUI as well as in the chat history window.

Equipment List

The equipment needed for the Networked Home Theater is minimal. The majority of the project is software based. Figure 7 lists the required equipment.

Equipment Needed

Hardware

EMAC development board

Sony CD player

Host PC

Software

Web Server

FTP Server

WinAmp

Web Browser

Shoutcast Streaming Media Server

Shoutcast DSP WinAmp Plugin

Netshow Tools

Virtual Networked Computer (VNC)

Figure 7 – Required Equipment

Several components for the Networked Home Theater had to be outsourced. The streaming audio server and client programs are both third party programs. That aspect of the project is out of scope for the goals to be accomplished in the Networked Home Theater project.

The Netshow Tools contain an encoding codec for streaming audio for speeds up to 56k. There are other codec’s that allow higher quality streaming, but the Netshow Tools are free. The Shoutcast DSP WinAmp plugin allows audio on the line in port of the soundcard to be encoded and streamed over the Internet.

The streaming audio allows the user to have some feedback from the system, but it inherently has a large problem. In order to broadcast and receive streaming audio over the Internet, the audio must be buffered at the client. This buffering causes the audio to be delayed by approximately 40 seconds. This is a problem because most users don’t have the patience to wait for 40 seconds after pressing a button.

Project Timeline

Week Date Work to be Completed

1 January 25 Complete Microprocessor Software

2 February 1 Complete Microprocessor Software

3 February 8 Write Control Server

4 February 15 Write test applet to explore commands

5 February 22 Find all possible S-Link commands

6 March 1 Write Applet

7 March 8 Write Applet

8 March 22 Write chat server

9 March 29 Write CDDB interface code

10 April 5 Test system with large user load

11 April 12 Prepare for Expo

12 April 19 Write final project report

13 April 26 Prepare for final project presentation

Figure 8 – Project TimeTable

Figure 8 was my estimated timeline for completion of the project. However, the dates listed changed due to the complexity of each phase of the project.

Week Date Work to be completed

1 January 25 Complete Microprocessor Software

2 February 1 Complete Microprocessor Software

3 February 8 Complete Microprocessor Software

4 February 15 Complete Microprocessor Software

5 February 22 Complete Microprocessor Software

6 March 1 Complete Microprocessor Software

7 March 8 Complete Microprocessor Software

8 March 22 Complete Microprocessor Software

9 March 29 Complete Microprocessor Software

10 April 5 Write Control Server

11 April 12 Write Control Server

12 April 19 Write Applet

13 April 26 Write chat server

Figure 9 – Project TimeTable

There are numerous reasons that the two timelines differ so vastly. First, the microprocessor code presented a much larger challenge than I anticipated. I did have the framework for the microprocessor code completed in a relatively short amount of time, but I did spend the majority of the time debugging the already written code. The best solution for spending so much time debugging would be to write the initial code slower with greater quality. The Java code did not present a very large problem, mainly because Dr. Malinowski provided the skeleton for the server. The final version of the server and applet were first made functional, which took about 1 day to do. Next, both the server and the applet were improved. It was in that fashion that I completed the final portion of the project.

There are several parts of the project that are uncompleted. The Networked Home Theater does not connect to CDDB.com to retrieve CD information. Because of this, the applet is not capable of advanced play list features. These incomplete steps are inconsequential, and the project is considered complete.

Appendix A - S-Link Commands

The following text is a reverse engineered command list of the Sony S-Link protocol. This work is public domain located on the Internet.

#

# Sony CD changer protocol description file.

#

# Careful! This is used to both document the protocol and

# is parsed to build the table of commands and messages.

#

Command: 00 play

Response: power_on,playing

Response: playing

Turns on the player if it is not already on and starts playing.

Unpauses if the player is currently in a paused state

Command: 01 stop

Response: stop

Stops the player. The current position is lost; the disc

restarts at the begining.

Command: 02 pause_on

Response: pause

Pauses the player. Resume with play or pause_toggle

Command: 03 pause_toggle

Response: pause

Response: playing

Pauses the player if it is player, plays if it is paused.

Just like hitting the button

Command: 08 next_track

Response: track_info

Response:

The player skips to the next track if there is one and

outputs the track information. If it is currently on

the last track of the disc nothing is done.

Command: 09 prev_track

Response: track_info

The player restarts the current track, or if at the beginning

of the current track it goes to the previous track.

Command: 0f mode

Response: mode

Requests a current mode message from the player. The player

responds with a very informating mode message.

Command: 10 fwd

Command: 11 rew

Command: 12 fast_fwd

Command: 13 fast_rew

The player cues forward/backwards at one of two speeds. Track

boundary messages are still emitted

Command: 20 disable

Command: 21 enable

Disables/enables the front panel controls on the player. Only

the Open button is still enabled once turned off.

Command: 22 capacity

Response: capacity

Asks the player how many discs it can hold

Command: 25 verbose

Response: status

In verbose mode the player outputs status information every second

until a new disc starts. Why it doesn't stay on is beyond me.

Command: 26 silent

Disables per-second reporting of status.

Coomand: 2e power_on

Response: power_on,now_at,capacity

Response:

Turns on the player if it is off and causes it to output a

set of status information. If it is already on, no output

is sent.

Command: 2f power_off

Response: power_off

Response:

Turns off the player if it is on. If it is already off

no output is sent.

Command: 40 get_memo disc

Response: memo_text

Error: no_memo

Retrieves the memo text for the specified disc

Command: 42 get_group group

Response: group_id

Error: already_did_that

Returns a string that represents the group's name.

Command: 43 group_list group

Response: disc_list1, disc_list2

Error: already_did_that

Error: error13

Requests a bit vector of which discs are in a certain group

Command: 44 disc_info disc

Response: disc_info

Error: invalid_disc

Requests the information on the requested disc, which must be

the currently loaded one. Otherwise the invalid_disc error

is returned.

Command: 45 track_length disc track

Response: track_length

Error: invalid_track

Requests the length of a track of the current disc. invalid_track

is returned for a track that is out of range or if the specified

disc is not currently loaded.

Command: 46 unknown46

Error: already_did_that

Command: 47 unknown46

Error: already_did_that

Command: 48 get_memo2 disc

Response: memo_text2

Error: no_memo

I don't know how memo_text2 differs from memo_text. Maybe for

CD Text volumes...

Command: 4a unknown4a byte

Response: msg5d, msg1d

Don't know what this ones does. The 0x5d response has a byte

that is the same as the argument to 0x4a.

Command: 50 play_track disc track

Error: no_such_disc,no_such_disc2

Response: going_to, unloading, now_at, toc_read, ready, track_info

Response: track_info

Loads and plays the requested track. If the track index is not

present then track 1 is played instead. If the disc is not present

the no_such_disc error is returned (followed by the no_such_disc2

error for somereason).

Command: 51 cue_track disc track

Error: no_such_disc,no_such_disc2

Response: going_to, unloading, now_at, toc_read, ready, track_info

Response: track_info

The same semantics as the play_track command

Command: 5e fade seconds

Error: already_did_that

Response:

Fades out the audio over the specified number of seconds. The

disc continues playing, but is muted. If the audio is already

faded the player emits the already_did_that error.

Command: 5f ramp seconds

Error: already_did_that

Response:

Ramps the audio back up over the specified number of seconds.

If the audio is already at full the player emits the already_did_that

error.

Command: 63 unknown63 disc

Response: msg63

Response: msg19

Error: already_did_that

Requests something about the current disc. msg63 has a null byte

followed by six bytes of data. Not sure what they mean...

already_did_that is returned if this is not the current disc.

Sometimes responds with a msg19

Command: 64 unknown64

Response: msg1a

Response: msg64

No clue what this does...

Sometimes it is a simple msg1a, sometimes a msg64 with nine

bytes of data that vary based on which track is playing.

Command: 6a type

Response: type

Requests a type message from the player. The type encodes an ID

string for the model of the player. Useful!

Command: 72 disc_list

Response: disc_list1, disc_list2

Requests a bit vector of which discs are present. Very, very cool.

Command: 80 set_memo disc string

Response: memo_written

Error: already_did_that

Writes the string of up to 14 characters for the specified disc.

If the disc has CD Text information the player will not allow

it to be overwritten.

Command: 81 unknown81

Error: already_did_that

 

Command: 90 dump_memo

Causes the player to dump memo texts for each disc in order.

#

# Messages are either sent in response to S-Link commands or generated

# by someone pressing a button on the front panel

#

Message: 00 playing

Sent by the player when it resumes playing.

Message: 01 stop

The player has stopped.

Message: 02 pause

The player has paused.

Message: 05 no_such_disc2

The requested disc does not exists. I believe that this is

a backwards compatible message.

Message: 06 unloading

The current disc is being returned to the carrosel.

Message: 08 ready

The player has read the table of contents and is now

going to start playing?

Message: 0c 30_seconds

There are 30 seconds left in the current track, not counting

pregap.

Message: 0f error

Something you did caused an error.

Message: 10 no_memo

There is no memo text for the disc that was requested.

Message: 13 invalid_group

Very few operations reference groups. I don't remember how

I found this one.

Message: 14 invalid_disc

The disc you wanted is out of range or not loaded.

Message: 15 invalid_track

The track you requested is out of range.

Message: 19 msg19

Error response to unknown63?

Message: 1d msg1d

The player received an unknown4a command.

Message: 1f memo_written

The set_memo command succedded

Message: 40 memo_text disc string

The memo text for the disc that was requested.

Message: 42 group_id group string

The name of the specified disc group. I don't know how to

change this yet.

Message: 43 group_list1 group disc_vector1

Message: 44 group_list2 group disc_vector2

A bit vector of all discs in a specified group. vector1 is

discs up to 104, vector2 is 105 up to 200.

Message: 48 memo_text2 disc string

I don't know what the difference is between these two.

Message: 50 track_info disc track min sec

When the player crosses a track boundary or begins playing

a new track it outputs this message.

Message: 51 status track index min sec

When verbose mode is turned on these messages are output every

second. I don't know what index means and am bothered by

the lack of a disc number. Grr.

Additionally, there are bugs with the way this handles

crossing a minute boundary. Usually four or five copies of

the status message for x:00 are output in the second.

Weird.

Additionally, this count does not include pregap; it is

what is displayed on the LCD. However, the track_length

message does include pregap. Go figure.

Message: 52 toc_read disc

The player had read the table of contents from the disc

and can answer queries about it now.

Message: 53 no_such_disc disc

The requested disc does not exist.

Message: 54 going_to disc

When the player is told to go to another disc, this is the

message that it outputs.

Message: 58 now_at disc

The player has rotated the carosel to the specified disc

and is going to load it.

Message: 5d msg5d byte

The player received a unknown4a command.

Message: 60 disc_info disc index tracks min sec frames

The current disc, the number of tracks and the overall

length in m:s:f. I don't know how accurate this value

is for CDDB calculations.

Message: 61 capacity disc

The capacity of the player in discs.

Message: 62 track_length disc track min sec

The length of the requested track in min:sec.

Message: 63 msg63 @bytes

Who knows? Sometimes sent in response to unknown63 commands.

Message: 64 msg64 @bytes

Message: 6a type string

The model ID of the player

Message: 70 mode playing program unknown2 disc track

In response to a mode command the player responds with this

message. Playing is 1 for playing, 2 for paused. program

has something to do with which program is currently playing.

I don't know what unknown2 is.

Message: 72 disc_list1 disc_vector1

Message: 73 disc_list2 disc_vector2

A bit vector of all discs present in the changer. vector1 is

up to 104. Vector2 is 105 up to 200.

 

Appendix B - Firmware Code

The following assembly code is the firmware code for the 80515 microprocessor.

$NOMOD51 ; omit assembler micro definitions

$include(reg515.inc) ; define 515 micro

PUBLIC oven_init

EXTRN CODE (oven_main)

; Define stack, 128 bytes of internal RAM for 8051

stack_begin EQU 60H ; allow 32 bytes for stack to start:

; 60-7FH

; I like to know exactly were it starts and ends

; stack problems very common with students

; Define starting location for program

stard EQU 0000H ; start address for program

PUBLIC SLINKWRITE

PUBLIC BUSREAD

PUBLIC ZEROCOUNT

PUBLIC ONECOUNT

PUBLIC SERWRITE

PUBLIC SLINKREAD

;--------------------------------------------------------------

; DATA SEGMENT--Reserves space in DATA RAM--128 bytes

;--------------------------------------------------------------

iram SEGMENT DATA ; segment for DATA RAM.

RSEG iram ; switch to this data segment

BUSREAD: DS 1

ZEROCOUNT: DS 1

ONECOUNT: DS 1

SERWRITE: DS 1

SLINKWRITE: DS 1

SLINKREAD: DS 1

;--------------------------------------------------------------

; Provide an LJMP to start at the reset address (address 8000H)

; in the main module.

;--------------------------------------------------------------

CSEG AT stard ; absolute Seg at 8000H

begin: LJMP start ; reset location

;---------------------------------------------------------

; Interrupt Vector Table

; Area

;---------------------------------------------------------

CSEG AT stard+0BH ; 0BH=addr for Timer 0

LJMP tmr0srv

CSEG AT stard+13h ; External interrupt 1.

LJMP ext1srv

CSEG AT stard+1BH ; Timer 1 interrupt.

LJMP tmr1srv

CSEG AT stard+23H ; Serial interrupt

LJMP serialsrv

CSEG AT stard+2BH ; Timer 2

LJMP tmr2srv

CSEG AT stard+43H ; IADC interrupt.

LJMP iadcsrv

CSEG AT stard+4BH ; IEX2 interrupt.

LJMP iex2srv

CSEG AT stard+53H ; IEX3 interrupt.

LJMP iex3srv

CSEG AT stard+5BH ; IEX4 interrupt

LJMP iex4srv

CSEG AT stard+63H ; IEX5 interrupt.

LJMP iex5srv

CSEG AT stard+6BH ; IEX6 interrupt.

LJMP iex6srv

;****************************************************

tmr0srv:

push acc

push b

push psw

mov a, BUSREAD ;check data send?

cjne a, #1h, interruptexit ;don't do anything if no data is being sent

mov c, P1.0 ;read from s-link

jnc addzerosample ;increment zero count

addonesample:

mov a, ONECOUNT ;increment ones counter

inc a ;increment ones counter

mov ONECOUNT, a ;increment ones counter

cjne a, #10h, testzeros ;if more than 8 ones, the data is finished

mov ONECOUNT, #0h ;reset the ones counter

mov BUSREAD, #0h ;the data is finished. Stop reading.

mov SERWRITE, #1h ;set the serial write byte

mov a, #0Ah

movx @DPTR, a

mov DPTR, #0FC00h ;set data pointer to beginning of array

ljmp interruptexit ;data done, so exit subroutine

testzeros:

mov a, ZEROCOUNT

cjne a, #0h, continuezeros

ljmp interruptexit

continuezeros:

mov a, ZEROCOUNT ;read zero count

mov b, #20 ;test for syncronization

subb a,b ;zero count - 20

jnc sync ;no carry. more than 20 zeros. It's a sync

clr c

mov a, ZEROCOUNT ;read zero count

mov b, #9 ;test for one

subb a,b ;zero count - 9

jnc one ;no carry. more than 9 zeroes, but less than 20.

;It's a one

zero:

mov a, #30h

movx @DPTR, a ;store a zero in data array

inc DPTR ;move to next array location

mov ZEROCOUNT, #0h ;reset zero counter

mov ONECOUNT, #0h ;reset one counter

sjmp interruptexit

one:

mov a, #31h

movx @DPTR, a

inc DPTR

mov ZEROCOUNT, #0h ;reset zero counter

mov ONECOUNT, #0h ;reset one counter

sjmp interruptexit

addzerosample:

mov ONECOUNT, #0h ;reset one counter

mov a, ZEROCOUNT ;increment zero counter

inc a ;increment zero counter

mov ZEROCOUNT, a ;increment zero counter

sjmp interruptexit

sync:

mov ZEROCOUNT, #0h ;reset zero counter

mov ONECOUNT, #0h ;reset one counter

interruptexit:

pop psw

pop b

pop acc

RETI

;*********************** S-Link Output **********************

tmr2srv:

cpl p1.4

push acc ;store data values

push psw

mov a, SLINKWRITE ;test if I should run

cjne a, #1h, noslinkout ;if slinkwrite=1 I run

cpl p1.5

mov a, R1 ;read pointer value from R1

inc R1 ;point to next data entry

movc A, @A+DPTR

cjne a, #31h, slinkzero

setb p1.0

sjmp nextslink

slinkzero:

cjne A, #30h, slinkdone

clr p1.0

sjmp nextslink

slinkdone:

cpl p1.6

setb p1.0

mov SLINKWRITE, #0h

mov SLINKREAD, #1h

mov DPTR, #0FC00h

nextslink:

noslinkout:

pop psw

pop acc

clr TF2 ;Re-enable timer interrupt

RETI

;********************** S-Link Output **********************

tmr1srv: RETI

ext1srv: RETI

serialsrv: RETI

iadcsrv: RETI

iex2srv: RETI

iex3srv: RETI

iex4srv: RETI

iex5srv: RETI

iex6srv: RETI

;---------------------------------------------------------

;

; End of Interrupt Service Routines

;

;---------------------------------------------------------

 

 

oven_init SEGMENT CODE

RSEG oven_init ; switch to this code segment

USING 0 ; use register_bank 0

; for the following program code.

T0CNT_H equ 0a5h ; timer 0 count high

T0CNT_L equ 0a5h ; timer 0 count low

T1CNT_H equ 0fdh ; timer 1 count high

T1CNT_L equ 0fdh ; timer 1 count low

T2CNT_H equ 0FDh ; timer 2 count high

T2CNT_L equ 0CFh ; timer 2 count low

start:

MOV SP,#stack_begin ; assign stack at beginning

MOV IEN0,#0 ; DISABLE ALL INTS

; * 80535 stuff

SETB P5.5 ; do a reset

CLR P5.5 ; bring it low

SETB P5.0 ; make A16 of 128K Ram, high

CLR P5.2 ; disable EEPROM

; note new port 5.1 setup

; required for LCD

CLR P5.1 ; enable MMIO (memory mapped IO)

MOV R0,#0FFH ; clear 256 bytes of RAM

clr_ram:

MOV @R0,#0 ; not required but good for debugging

DJNZ R0,clr_ram

anl PCON,#7Fh

mov TMOD,#20h

mov TCON,#40h

mov SCON,#52h

MOV A,TMOD ; timer 0: 8-bit autoreload

SETB ACC.1 ; don't change other bits

MOV TMOD,A

MOV IP0,#2 ; set Timer 0 for highest priority

SETB T2CON.0 ; timer 2: 16 bit operation

SETB T2CON.4 ; and auto-reload mode

; initialize timer 0

MOV TH0,#T0CNT_H ; for 11.0592Mhz crystal

MOV TL0,#T0CNT_L ; high,low bytes for 100us

MOV TH1,#T1CNT_H

MOV TL1,#T1CNT_L

MOV TH2,#T2CNT_H ; initialize timer 2

MOV TL2,#T2CNT_L ; for 500 us interrupt

MOV CRCH,#T2CNT_H ; load capture registers

MOV CRCL,#T2CNT_L ; for timer 2

SETB TR0 ; start timer 0

SETB ET0 ; enable timer 0 ovf int

SETB ET2 ; enable timer 2 ovf int

SETB EAL ; enable all interrupts

mov ZEROCOUNT, #0h ;Zero counter for cd read function

mov ONECOUNT, #0h ;ones counter

LJMP oven_main ; go jump into main loop

END

$NOMOD51 ; omit assembler micro definitions

$Include(reg515.inc) ; define 515 micro

PUBLIC oven_main

EXTRN DATA(BUSREAD, SERWRITE, SLINKREAD, SLINKWRITE)

main SEGMENT CODE

RSEG main ;switch to this code segment

USING 0 ;use register_bank 0

;for the following module

oven_main:

mov BUSREAD, #0h ;CD-Bus read bit

mov SERWRITE, #0h ;write to serial enable; 0 = false; 1 = true

mov SLINKREAD, #1h

mov SLINKWRITE, #0h

clr RI ;enable serial read

mov DPTR, #0FC00h ;set data array location

mov R0, #0h

;******************** Main Loop **********************

control_loop:

mov a, SLINKWRITE ;don't do any thing if writing to s-link

cjne a, #0, control_loop

mov a, SERWRITE

cjne a, #1h, noserialout

acall com0out

sjmp control_loop ;don't do anything else if writing to serial

noserialout:

mov a, SLINKREAD

cjne a, #1h, serrun

clr c

mov c, P1.0 ;Check bus to see if data is being sent

jc serrun

mov BUSREAD, #1h ;Set read bit

serrun:

mov a, BUSREAD ;don't read from serial port if reading from s-link

cjne a, #0h, control_loop ;busread=1 means reading s-link

mov a, SERWRITE ;Don't read from serial port if reading from serial

cjne a, #0h, control_loop

cpl p1.1

jnb RI, control_loop ;stay in loop until serial data

cpl p1.2

mov SLINKREAD, #0h ;disable s-link read ability

mov BUSREAD, #0h ;disable s-link read interrupt

mov DPTR, #0FC00h ;reset data array to start

cominloop:

jnb RI, $

mov a, sbuf

clr RI

cpl p1.3

movx @DPTR, a

inc DPTR

cjne a, #31h, notaone

sjmp cominloop

notaone:

cjne a, #30h, notvalid

sjmp cominloop

notvalid:

mov DPTR, #0FC00h ;Reset Array Pointer

mov SLINKWRITE, #1h ;Enable interrupt to write to s-link port

mov R1, #0h

serialexit:

sjmp control_loop

;******************** Main Loop **********************

;****************** S-Link to Com0 *******************

com0out:

mov DPTR, #0FC00h

mov R0, #0h

comoutloop:

mov a, R0 ;array count

inc R0

jnb TI,$

clr TI

movc A, @A+DPTR

mov SBUF,a ;write the data in Acc to serial buffer

cjne a, #0Ah, comoutloop

comoutdone:

mov SERWRITE, #0h ;disable serial write enable

ret

;****************** S-Link to Com0 *******************

end