Este raz: Jak naprogramovat jeste jednu RS232 u AT89C2051

Wek wek at evona.sk
Fri May 11 16:18:10 CEST 2001


Nie je to pekne ani presne ani optimalne, ale na uvod by to mohlo byt ako
inspiracia.
Vysielac je robota pre deti ;-).

Jano Waclawek



RXDTIM                  EQU     174     ;(11059200/12/9600)
                                        ;(174 pre 20MHz)
RXDD                    bit     p3.3    ;Vstup obvodu MAX232: R1O
DSEG                    AT      30H
RxByte:                 ds      1       ; Rezervovanie 1 bajtu pre RxByte
CSEG

               org     0013h           ;Vektor externeho prerusenia 1
                jmp     RXD_Signal
                RETI

                org     001bh           ;Preplnenie casovaca 1
                jmp     RXD_Timer       ;Casovac1 zodpoveda za kom. cez ser.
kanal
                RETI
;***** RXD signal - start bit
****************************************************************************
*************

RXD_Signal:     mov     TL1,#100h-(3*RXDTIM/2)+20  ;+ 20 pre 20mhz
                clr     TF1                     ;vymazat flag od timer 1
                setb    ET1                     ;povolit prerusenie od timer
1
                clr     EX1                     ;zastavit prerusenia od
start bitu
                 mov     RxByte,#080h            ;data na 8 bits
                setb    TR1                     ;nastartovat timer1
                setb    PT1                     ;nastavit priotitu na timer
1
                RETI
;***************************************************************************
*******************************************



;***** RS 232 SUBROUTINES
****************************************************************************
*****************

RXD_Timer:      push    dph
                push    dpl
                push    psw
                push    acc
                push    0

                mov     a,RxByte
                mov     C,RXDD
                rrc     a
                mov     RxByte,a
                jnc     RXD_T1J
                jmp     CatchByte

RXD_T1J:        jmp     RXD_T1


CatchByte:
                                ;zachyteny cely bajt v RxByte, uz len ho
spracovat - malo by sa to stihnut pocas stop-bitu.

              clr     ET1                     ;zastavit timer1
                clr     IE1                     ;vymazat flag od hrany start
bitu
                setb    EX1                     ;povolit interrupt od start
bitu
                setb    px1                     ;nastavit prioritu na hranu
ex1

RXD_T1:         pop     0
                pop     acc
                pop     psw
                pop     dpl
                pop     dph

                RETI








More information about the HW-list mailing list