;------------------------------------------------- ;Program: MOD-Comp.ASMatable ;Update: 21 August 2002 ;Initial: 17 October 1991 ; ;By: Dr. Marcus O. Durham, PhD, PE ; Tulsa, OK, USA ; mod@superb.org ; www.ThewayCorp.com ;Copyright (c)1991, 2002. All rights reserved ; ;Purpose: ; A set of routines are provided to perform the ; basic functions of a computer. ; ; These include ports, timers, serial RS232, ; mmio, keypad, seven segment display, ; liquid crystal display, and analog/digital ; convert. ; ;Processor: 8031 family ;PROM: 8k (2000H) onboard ;Crystal: 11.059 MHz ;Baud: 9600 ;Handshake: not used at this speed ;Assembler: Intel ASM51 ; ; There are three types of processing techniques ; that are used. ; MAIN - is the normal loop processing ; INTERRUPTS- occur based on events, such as ; regular time intervals. ; BUSY - is called for random tasks that ; can be processed during the delay ; in other tasks. Keypad scan ; is a prime example. ; ;------------------------------------------------- ;ASSEMBLERS ;------------------------------------------------- ; ; Several assemblers are available for the 8051. ; The major differences are in the syntax of ; the directives. The three that I have used are ; compared. ; ; ; TASM.EXE is a table lookup. ; tasm -51 -p -l Bios11v2.asm ; .ORG 0050h ;Next inst @ 0050H ;Value .EQU 12h ;predefined value ;Table .BYTE 34h ;define code byte ; .TEXT "123" ;define ascii ; .END ;last thing ; ; ; A51.EXE is student version of PseudoCodes. ; A51 -s Bios11v2.asm ; .ORG 0050h ;Next inst @ 0050H ; .EQU label,12h ;Table: .DB 34h ;define code byte ; .DB "123" ;define ascii ; ; ; ASM51.EXE is Intel assembler with library. ; ASM51 Bios11v2.asm ; ORG 0050h ;Next inst @ 0050H ;Value EQU 12h ;predefined value ;Table: DB 34h, '123' ;define code storage ; END ;last thing ; ; ;------------------------------------------------- ;FORMAT ;------------------------------------------------- ; ; The format of the code lines is shown. This ; gives space for opcodes in the *.lst files ; to fit on one line of display & print. ; ;LABEL: MNEMON OPERAND ;COMMENTS ;Columns 1 1 2 3 4| ; 1 8 4 1 9 ; ;------------------------------------------------- ;EXTERNAL -VS- INTERNAL PROM ;------------------------------------------------- ; ; 8051 has external memory on prom ; 8951 has 4K (07ffH) internal flash eprom ; 898252 has 8K flash & 2K eeprom ; ; To program 8051, burn an external prom/eeprom. ; To program low memory of 8951, burn flash ; To program 898252, program using SPI to Port 1. ; P15 = MOSI ; P16 = MISO ; P17 = SCLK ; Gnd = common ; Use program AEC_ISP.exe to download from PC ; ; When the uP is reset, it looks at EA'. ; If EA'=0, then external eprom is read. ; ; IF EA'=1, then internal eprom is read. ; Internal eprom is executed until it hits end. ; Then external eprom is used, even if EA'=1. ; ; EA' is pin 31. ; To begin program from prom, strap EA' to 0. ; To use the internal flash, strap EA' to 1. ; ;------------------------------------------------- ; ; The 8951 has 4K (0FFFh) internal flash prom. ; Make the last internal executable line be 0FFFh ; The next instruction will be 1000h on external ; prom/sram. ; So, ORG the external program to 1000H. ; Initially make program organize to hi memory. ; ORG 1000H ;external ; ; If it is moved to low memory (onboard flash), ; the address must be known so the hi memory can ; call the routine. ; For example in low memory ; ORG 0250H ;Next inst @ 0250H ;SCRNDATA:MOV ;low mem routine ; ; The high memory PROM/SRAM overlays the same ; space. It is just not available to the uC. ; However, this little feature lets us place ; an ORG directive to the assembler at the same ; location. It will never be executed. Program ; Control will go to the low memory ; ORG 0250H ;pseudo location ;SCRNDATA:NOP ;just for assembler ;################################################# ; ; ASSIGNMENTS ; ;################################################# ; ; Assignments include ; 1. constants for symbols and sizes ; 2. constants for ext mmio addresses ; 3. variables assigned to internal RAM locations ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;CONSTANTS ;------------------------------------------------- ;SYMBOLS Scrl EQU 42d ;scroll key,"*",2AH Entr EQU 35d ;enter key,"#",23H None EQU 0FFH ;blank key Flash EQU 254 ;black cursor for flash Colon EQU 3AH ;colon Zero EQU 30H ;zero character Slash EQU 2FH ;slash DecPt EQU 2EH ;decimal point Minus EQU 2DH ;minus sign CRet EQU 13d ;carriage return DigX EQU 8 ;number of decimal digits MathX EQU 4 ;number of hexidecimal bytes ;------------------------------------------------- ;EXTERNAL ADDRESS FilAdH EQU 00 ;address file base for DPH FilAdL EQU 50H ;for DPL, base addr= 0050H AdConR EQU 8000H ;MMIO addr Control Register AdKeyP EQU 8000H ;MMIO addr for Keypad latch AdLcdD EQU 8000H ;MMIO addr for LCD data lat AdSevS EQU 8000H ;MMIO addr for Seven Seg AdExtW EQU 8000H ;MMIO addr for external wr AdExtR EQU 8000H ;MMIO addr for external rd ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;STACK ;------------------------------------------------- ; ; The stack is moved up high to prevent it from ; overwriting data. Stack counts up from the next ; location past the stack pointer base. ; ; The default stack location is 07H. It will over ; write the registers. ; ; Two bytes are used by each interrupt and each ; subroutine call. So enough stack space must be ; reserved for nested loops. ; ; ;STACK RESERVED ; EQU 5FH ;Move stack to 60H & above ; ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;USER VARIABLES ;------------------------------------------------- ; ; All the RAM locations I used are shown below. ; This is so the user will not overwrite them. ; ; Place any user variables within this range. ; ;------------------------------------------------- ;USER DEFINED VARIABLES ;place user variable here ; EQU 5FH ; ;and everything in between SbcTeam2 EQU 40h ;count team 1 SbcTeam1 EQU 3Fh ;count team 1 TimMin EQU 3EH ;time minutes counter TimSec EQU 3DH ;time seconds counter TimPer EQU 3CH ;time periods counter ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;DEFINED VARIABLES ;------------------------------------------------- ; ; Defined variables are used by many routines. ; These are fixed locations that should not be ; changed since the order is critical to SqROOT. ; ; Note that the math variables ArgX, RemX, FraX ; locations are shared with TmpX and GapX ; Math procedures are seldom done. When they are, ; the process is completed before other functions ; are attempted. Therefore, there is no conflict. ;Gap is scratch, display ;Tmp is temporary register ;Hex =32 bit working reg ;ORDER CRITICAL TO SQ ROOT FraD EQU 3BH ;4 bytes used in divide FraC EQU 3AH ;same space as Gap upper FraB EQU 39H ; FraA EQU 38H ; RemD EQU 33H ;4 digit remain RemC EQU 32H ;same space as Tmp upper by RemB EQU 31H RemA EQU 30H SizeT EQU 33H ;same space as Tmp upper by ArgG EQU 32H ;used in multiply ArgT EQU 31H ArgH EQU 30H GapH EQU 3BH ;8 digit GapG EQU 3AH ;BCD digits high BYTE GapF EQU 39H ;& intermediate value hold GapE EQU 38H GapD EQU 37H GapC EQU 36H GapB EQU 35H GapA EQU 34H TmpH EQU 33H ;8 byte TmpG EQU 32H TmpF EQU 31H TmpE EQU 30H ;Delay routine TmpD EQU 2FH TmpC EQU 2EH ;RAM Init Valu, Init ea pas TmpB EQU 2DH ;RAM Test Valu, CPL ea addr TmpA EQU 2CH ;math low BYTE HexD EQU 2BH ;double word HexC EQU 2AH HexB EQU 29H ;16 bit register HexA EQU 28H ;low byte of variable ;------------------------------------------------- ; ;BITS LOCATION ; EQU 27H ;last byte reserved for bit ; EQU 20H ;first byte for bit usage ; ;------------------------------------------------- ;SCREENS ScnFil EQU 1FH ;File where data is stored ScnMem EQU 1EH ;bytes of memory required ScnGet EQU 1DH ;cursor loc present ScnCur EQU 1CH ;cursor loc desired & temp ScnDis EQU 1BH ;bytes of display space req ScnTyp EQU 1AH ;type data, if #, it is dp ;------------------------------------------------- ;BANK3 QikB EQU 19H ;Interrupt HEX value, msb QikA EQU 18H ;Interrupt HEX value, lsb ;------------------------------------------------- ;KEYS KeyCol EQU 17H ;present column number KeyBit EQU 16H ;byte moves a bit w/ column KeyRow EQU 15H ;row number pushed KeyMul EQU 14H ;multiple key count CharK EQU 13H ;key input character CharD EQU 12H ;debounced ;------------------------------------------------- ;BANK2 ;R1 EQU 11H ; ;R0 EQU 10H ; ;------------------------------------------------- ;CHARACTERS, HOLD, COUNT CharP EQU 0FH ;undebounced previous input CharL EQU 0EH ;character to LCD & Serial MenuL EQU 0DH ;loop @MENUS LatCr EQU 0CH ;control latch bits status ScnDph EQU 0BH ;hold DPH ScnDpl EQU 0AH ;hold DPL ;------------------------------------------------- ;BANK1 ;R1 EQU 09H ;SRAM address, interrupts ;R0 EQU 08H ;SRAM address, background ;------------------------------------------------- ;BANK 0, USE W/ MATH & LOOP LoopC EQU 07H ;loop counter Size EQU 06H ;multiply, divide, sqrt, GP ;R5 EQU 05H ;carry in multiply, GP ;R4 EQU 04H ;carry in mul,GP ;R3 EQU 03H ;loop 2, math ;R2 EQU 02H ;loop, destination size,mat ;R1 EQU 01H ;source indirect addr,math ;R0 EQU 00H ;destination indirect addr ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;BITS ASSIGNMENTS ;------------------------------------------------- ; ;AT RAM BYTE 20H FgC BIT 01H ;temporary for C, etx FgKeyH BIT 00H ;flag key held down ;+++++++++++++++++++++++++++++++++++++++++++++++++ ;SPECIAL FUNCTION REGISTERS ;------------------------------------------------- ; ; SFR are listed for information. With limited ; assemblers, remove the ; since the address must ; be defined. ; ; ;SFR DEFINED ;B EQU 0F0H ;second math register ;Acc EQU 0E0H ;accumulator ;PSW EQU 0D0H ;processor status word ;IP EQU 0B8H ;interrupt priority ;P3 EQU 0B0H ;port 3 ;IE EQU 0A8H ;interrupt enable ;P2 EQU 0A0H ;port 2 ;SBUF EQU 99H ;serial buffer ;SCON EQU 98H ;serial control ;P1 EQU 90H ;port 1 ;TH1 EQU 8DH ;timer hi BYTE 1 ;TH0 EQU 8CH ;timer hi BYTE 0 ;TL1 EQU 8BH ;timer lo BYTE 1 ;TL0 EQU 8AH ;timer lo BYTE 0 ;TMOD EQU 89H ;timer mode ;TCON EQU 88H ;timer control PCON EQU 87H ;power control reg ;DPH EQU 83H ;data pointer hi ;DPL EQU 82H ;data pointer low ;SP EQU 81H ;stack pointer ;P0 EQU 80H ;port 0 ;------------------------------------------------- ;BIT IN SFR Acc7 EQU 0E7H ;Accumulator bit 7 Acc6 EQU 0E6H ;accum bit 6 BankH EQU 0D4H ;PSW register bank high bit BankL EQU 0D3H ;PSW register bank low bit Over EQU 0D2H ;PSW bit 2, overflow on add ;P EQU 0D0H ;parity, PSW ;TI EQU 99H ;transmit is complete ;RI EQU 98H ;receive is complete ;TR1 EQU 8EH ;timer 1 start ;TF0 EQU 8DH ;timer 0 overflow ;TR0 EQU 8CH ;timer 0 start ;------------------------------------------------- ;PORT USE P33 EQU 0B3H ;Port33 Hi=PC Busy,uP no xm ;Not always used in prog ;to use, SETB P33 for input P35 EQU 0B5H ;Port35 Hi=uP BUSY,stop ser ;xmit to uP in download mod ;SPI ADC LINES ;move when know real locate SpMosi EQU 0B2H ;SPI data out, INT0, P32 SpMiso EQU 0B4H ;SPI data in, T0, P34 SpCLk EQU 0B5H ;SPI serial clock, T1, P35 SpCS EQU 4 ;SPI ADC CS Con latch D4 SpConv EQU 5 ;SPI ADC Cnv Con latch D5 ;################################################# ; ; PROGRAM ; ;################################################# START: ;------------------------------------------------- ; When processor is reset, program control comes ; here. Jump to the first executable address ; after all interrupts reserved locations. ORG 00H LJMP INITIAL ;************************************************* ; ; INTERRUPTS ; ;************************************************* ; ; Interrupt set-up is discussed in a later ; section. It is associated with timer/counters. ; ;------------------------------------------------- ;INTERRUPT-External 0 ;------------------------------------------------- ORG 03H RETI ;------------------------------------------------- ;INTERRUPT-Timer 0 ;------------------------------------------------- ; The procedure provides direction when timer ; completes count. ORG 0BH LJMP TIMECAL ;interrupt processor ;------------------------------------------------- ;INTERRUPT-External 1 ;------------------------------------------------- ORG 13H ;------------------------------------------------- ;INTERRUPT-Timer 1 ;------------------------------------------------- ; Timer 1 is used for serial. So this procedure ; will never be executed. ORG 1BH ;------------------------------------------------- ;INTERRUPT-Serial ;------------------------------------------------- ; This is not used. The bits are polled in ; various other routines. ORG 23H ;------------------------------------------------- ;COPYRIGHT ;------------------------------------------------- ; Federal statues require credit be given for ; the source of any information used. This ; section must be left with any code used from ; this program. ORG 002BH ;Address past vectors DB 0 ;null address = 2Ch DB 18, 1, 'Copyright (C) 2002' DB 25, 1, 'Marcus O. Durham, PhD, PE' DB 14, 1, 'Tulsa, OK USA' DB 0 ;null address = 6Eh ;************************************************* ; ; INITIAL & MAIN ; ;************************************************* ORG 0070H ;Addres past reserve ; ORG 1000H ;Address if external ;------------------------------------------------- INITIAL: ;------------------------------------------------- ; ; The procedure initializes all common routines. ; It directs traffic for initiation messages. ;INITIALIZE MOV SP,#5Fh ;start stack @ 5f+1 ;------------------------------------------------- MAIN: ;------------------------------------------------- ; ; The main procedure directs traffic. ; The main orchestrates execution of the ; subroutines. ; ; The procedures are for a scoreboard (SB). ;PROCESS MAN9: LJMP MAIN ;Repeat ;************************************************* END ;Program end