Difference between revisions of "CSC270 Homework 10"

From dftwiki3
Jump to: navigation, search
(Problem #1)
Line 22: Line 22:
 
Same question, but this time for sending a '0'.
 
Same question, but this time for sending a '0'.
  
If you put an RTS instruction at the end of your function, and call the first function SendOne, and the second function SendZero...
+
If you put an RTS instruction at the end of your function, and call the first function SendOne, and the second function SendZero, then you can write something like this:
 +
 
 +
 
 +
<code><pre>
 +
;--------------------------------------------------------------------
 +
; SendAsciiNEC.asm
 +
; takes the ascii code stored in the byte variable data and sends it
 +
; to output port at address 8000, which we assume is connected to an
 +
; infrared LED.
 +
; The protocole used is that of the NEC corporation, and fully described
 +
; in  http://www.sbprojects.com/knowledge/ir/nec.htm .
 +
;
 +
; All 8 bits are sent, one after the other. 
 +
; The program returns to the monitor when finished.
 +
;
 +
; The starting point is at label Start.
 +
;
 +
                org    0000
 +
saveB          FCB    0      ; variable to save AccB  in
 +
data            FCB    'A'    ; ascii code for 'A'
 +
 
 +
;--------------------------------------------------------------------
 +
;      MAIN PROGRAM
 +
; All 8 bits stored in byte data are sent, one after the other. 
 +
;
 +
                org    0010
 +
start:          ldab    #8      ; get ready to send 8 bits
 +
 
 +
 
 +
loop:          ldaa    data    ; get byte to send
 +
                anda    #1      ; get the least significant bit of Acca
 +
                cmpa    #1      ; is it 1?
 +
                beq    send1  ; if so go send a 1
 +
                jsr    SendZero; if not, send a 0
 +
                jmp    testEnd ; go to end of loop
 +
 
 +
Send1:          jsr    SendOne ; send a 1
 +
               
 +
testEnd:        ldaa    Data    ; get data
 +
                lsra            ; shift Acca 1 bit to the right
 +
                staa    Data    ; save it back in data
 +
                decb            ; decrement AccB
 +
                cmpb    #0      ; is it 0 yet?
 +
                bne    loop    ; no, still more bits to send
 +
                jmp    C000    ; done, return control to Monitor
 +
 
 +
;--------------------------------------------------------------------
 +
; SendOne: sends a '0' to the InfraRed LED at Port Address
 +
;          8000 using the NEC protocole presented at
 +
;          http://www.sbprojects.com/knowledge/ir/nec.htm .
 +
;          ACCB is not modified by the procedure.
 +
;          ACCA is very likely modified by the procedure.
 +
SendOne:        stab    saveB  ; save AccB
 +
 
 +
                ; your code goes here
 +
                .
 +
                .
 +
                .
 +
 
 +
                ldab  saveB    ; restore AccB
 +
                rts
 +
 
 +
;--------------------------------------------------------------------
 +
; SendOne: sends a '1' to the InfraRed LED at Port Address
 +
;          8000 using the NEC protocole presented at
 +
;          http://www.sbprojects.com/knowledge/ir/nec.htm .
 +
;          ACCB is not modified by the procedure.
 +
;          ACCA is very likely modified by the procedure.
 +
SendZero:      stab    saveB  ; save AccB
 +
 
 +
                ; your code goes here
 +
                .
 +
                .
 +
                .
 +
 
 +
 
 +
                ldab  saveB    ; restore AccB
 +
                rts
 +
 +
</pre></code>

Revision as of 12:10, 15 April 2009

--D. Thiebaut 18:51, 14 April 2009 (UTC)


UnderConstruction.jpg
UNDER CONSTRUCTION

Problem #1

CSC270 Sony IR remote signal.gif

This picture is taken from the following Web site: http://www.sbprojects.com/knowledge/ir/nec.htm .

It depicts part of a broader protocol for sending commands over infrared communication between a remote device and a receiver (consumer electronics device).

You will notice that to send a '1', the remot actually sends a burst (about 21 cycles) of a signal with a frequency of 38 KHz, followed by a gap with no activity with a duration of 2.25 ms - 560 us. Similarly, to send a '0', the remote sends the same burst of 38KHz (about 26 cycles), followed by a shorter gap of 1.12 ms - 560 us.

Write the assembly function that can be called to send a '1'. In other words, if we replaced your LED by an infrared LED, what is the program that the 6811 would have to execute to generate the first part of the waveform shown above?

Same question, but this time for sending a '0'.

If you put an RTS instruction at the end of your function, and call the first function SendOne, and the second function SendZero, then you can write something like this:


;--------------------------------------------------------------------
; SendAsciiNEC.asm
; takes the ascii code stored in the byte variable data and sends it
; to output port at address 8000, which we assume is connected to an
; infrared LED.
; The protocole used is that of the NEC corporation, and fully described
; in  http://www.sbprojects.com/knowledge/ir/nec.htm .
;
; All 8 bits are sent, one after the other.  
; The program returns to the monitor when finished.
;
; The starting point is at label Start.
;
                org     0000
saveB           FCB     0       ; variable to save AccB  in
data            FCB     'A'     ; ascii code for 'A'

;--------------------------------------------------------------------
;      MAIN PROGRAM
; All 8 bits stored in byte data are sent, one after the other.  
;
                org     0010
start:          ldab    #8      ; get ready to send 8 bits


loop:           ldaa    data    ; get byte to send
                anda    #1      ; get the least significant bit of Acca
                cmpa    #1      ; is it 1?
                beq     send1   ; if so go send a 1
                jsr     SendZero; if not, send a 0
                jmp     testEnd ; go to end of loop

Send1:          jsr     SendOne ; send a 1
                
testEnd:        ldaa    Data    ; get data
                lsra            ; shift Acca 1 bit to the right
                staa    Data    ; save it back in data
                decb            ; decrement AccB
                cmpb    #0      ; is it 0 yet?
                bne     loop    ; no, still more bits to send
                jmp     C000    ; done, return control to Monitor

;--------------------------------------------------------------------
; SendOne: sends a '0' to the InfraRed LED at Port Address
;          8000 using the NEC protocole presented at 
;          http://www.sbprojects.com/knowledge/ir/nec.htm .
;          ACCB is not modified by the procedure.
;          ACCA is very likely modified by the procedure.
SendOne:        stab    saveB   ; save AccB

                ; your code goes here
                .
                .
                .

                ldab   saveB     ; restore AccB
                rts

;--------------------------------------------------------------------
; SendOne: sends a '1' to the InfraRed LED at Port Address
;          8000 using the NEC protocole presented at 
;          http://www.sbprojects.com/knowledge/ir/nec.htm .
;          ACCB is not modified by the procedure.
;          ACCA is very likely modified by the procedure.
SendZero:       stab    saveB   ; save AccB

                ; your code goes here
                .
                .
                .


                ldab   saveB     ; restore AccB
                rts