Skip to content

Instantly share code, notes, and snippets.

@ryanseys
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanseys/745538f21eadf75d397f to your computer and use it in GitHub Desktop.
Save ryanseys/745538f21eadf75d397f to your computer and use it in GitHub Desktop.
NAME LAB3B
;*****************************************************************************
; B E G I N N I N G O F P R O G R A M
;*****************************************************************************
;-----------------------------------------------------------------------------
; E Q U A T E S
;-----------------------------------------------------------------------------
; 8255 Setup
CNTR_8255 EQU 0FFFEH ;Port control address
OUTPUT_MODE EQU 0B5H ;Set up mode for port B output
; 8255 Control
PORT_B_ADDR EQU 0FFFAH ;Port B address
; 8253 Setup
COUNT_CNTR EQU 000EH ;counter control register address
MODE2 EQU 74H ;____Counter 1 Mode 2: Rate Generator Mode
MODE3 EQU 36H ;____Counter 0 Mode 3: Square Wave Generator Mode
COUNT0 EQU 0008H ;counter0 address
COUNT1 EQU 000AH ;counter1 address
LO10MSEC EQU 0B4H ;___Low point of 10 mSec interval
HI10MSEC EQU 05FH ;___High point of 10 mSec interval
LO1SEC EQU 064H ;___Low point of 1 sec interval
HI1SEC EQU 000H ;___High point of 1 sec interval
; 8259A Setup
CLR_A0 EQU 0000H ;Which CW's written here? ____Control register address where A0=0
SET_A0 EQU 0002H ;Which CW's written here? ____Control register address where A0=1
ICW1 EQU 17H ;____Edge Triggered, call interval of 4, single mode, ICW4 needed
ICW2 EQU 20H ;____Set Vector Address for IR0 to T5=1
ICW4 EQU 03H ;____Not special mode, Non-Buffered Mode, Auto EOI, 8086/8 Mode
OCW1 EQU 0FCH ;____Enable interrupts 0 and 1, mask rest
; 8279 Setup
LED_RIGHT EQU 090H ;_____Address for the rightmost digit of the LED display
LED_CNTR EQU 0FFEAH ;Port number for 8279 control register
LED_DATA EQU 0FFE8H ;Port number for 8279 data register
;-----------------------------------------------------------------------------
; S T A R T O F V E C T O R S E G M E N T
;-----------------------------------------------------------------------------
VECTOR_SEG SEGMENT
ORG 00080H ;Interrupt vector: type 32 dec.
IR0_IP_VECT DW ? ;Low contains IP of ISR0
IR0_CS_VECT DW ? ;High contains CS of ISR0
IR1_IP_VECT DW ? ;Low contains IP of ISR1
IR1_CS_VECT DW ? ;High contains CS of ISR1
VECTOR_SEG ENDS
;-----------------------------------------------------------------------------
; S T A R T O F C O D E S E G M E N T
;-----------------------------------------------------------------------------
CODE_SEG SEGMENT
ASSUME CS:CODE_SEG, DS:DATA_SEG
ORG 00100H
;..............................................................................
; PROCEDURE : INIT
; - This procedure is called from the main program to initialize the
; 8253, the 8259A and the 8255.
;..............................................................................
INIT PROC NEAR
;Initialize the 8255 to set port B as output to DAC.
MOV DX,CNTR_8255 ; Port control address
MOV AL,OUTPUT_MODE ; Set up mode for port B output
OUT DX,AL
;Initialize 8253 counter0 and counter1 - counter2 is not used.
;Clock is the peripheral clock with frequency assumed to be 2.45MHz
;______Counter 0 to generate square waves with period of 10 mSec
;______Counter 1 to generate pulsed with period of 1 sec
MOV DX,COUNT_CNTR ;____Set counter 0 to mode 3: square wave generator
MOV AL,MODE3
OUT DX,AL
MOV DX,COUNT0
MOV AL,LO10MSEC ;____Set Counter 0 interval to 10 mSec
OUT DX,AL
MOV AL,HI10MSEC
OUT DX,AL
MOV DX,COUNT_CNTR ;____Set counter 1 to mode 2: Rate Generator
MOV AL,MODE2
OUT DX,AL
MOV DX,COUNT1
MOV AL,LO1SEC ;_____Set counter 1 interval to 1 sec
OUT DX,AL
MOV AL,HI1SEC
OUT DX,AL
;Initialize 8259A to :_____First ICW1 is used to set Edge Triggered mode,
; call interval of 4 and set to single mode, ICW4 needed. A0 = 0 at this
; point because we are doing ICW1. Then ICW2 is set (A0 = 1). ICW2 Sets the
; Vector Address for IR0 to T5=1 so we are using IR0 for interrupts.
; No ICW3 is used. ICW4 is used where its not special fully nested mode,
; Non-Buffered Mode, Auto EOI (End of interrupt) and obviously 8086/8 Mode.
MOV DX,CLR_A0 ;_____Write ICW1 to the control register with A0=0
MOV AL,ICW1
OUT DX,AL
MOV DX,SET_A0 ;_____Write ICW2 to the control register with A0=1
MOV AL,ICW2
OUT DX,AL
MOV AL,ICW4 ;_____Write ICW4 to the control register with A0=1
OUT DX,AL
;_____Enable interrupts 0 and 1 and disable the rest using the OCW1 control word.
MOV AL,OCW1 ;_____Write OCW1 to the control register with A0=1
OUT DX,AL
;Initialization complete, interrupts still disabled.
RET
INIT ENDP
;.............................................................................
; PROCEDURE : DAC_UPDATE
; - This procedure will be called by the ISR0 routine to update the
; DAC_MEMORY to produce a saw-tooth waveform through the 8255 PIP.
;.............................................................................
DAC_UPDATE PROC NEAR
PUSH DX ;Save register to be used.
PUSH AX
MOV DX,PORT_B_ADDR ;Increased the step voltage to
MOV AL,DAC_MEMORY ; DAC by 1 unit.
OUT DX,AL
INC DAC_MEMORY ;Store next value of voltage
POP AX
POP DX
RET
DAC_UPDATE ENDP
;..............................................................................
; INTERRUPT SERVICE ROUTINE : ISR0
; - This ISR will keep track of the time so is serviced every 10msec.
; When it is called, it calls the DAC_UPDATE procedure
; to output the sawtooth waveform (by incrementing the voltage).
;..............................................................................
ISR0 PROC NEAR
CALL DAC_UPDATE ;Update the DAC output
IRET
ISR0 ENDP
;..............................................................................
; INTERRUPT SERVICE ROUTINE : ISR1
; - This ISR is serviced every 1 second, displaying a changing
; garbage symbol on the SDK display.
;..............................................................................
ISR1 PROC NEAR
PUSH AX ;Save registers.
PUSH DX
MOV AL,LED_RIGHT ;____Load the LED addr. into the AL register.
MOV DX,LED_CNTR ;Address of control register
OUT DX,AL ;Load LED addr.-> control reg.
MOV DX,LED_DATA ;Address for data register
MOV AL,GARBAGE
DISP: INC AL ;Change GARBAGE CHAR.
OUT DX,AL ;Send to LED display
MOV GARBAGE,AL
POP DX ;Restore registers
POP AX
IRET
ISR1 ENDP
;..............................................................................
; S T A R T O F M A I N P R O G R A M
;..............................................................................
ASSUME DS:VECTOR_SEG ;offset relative to vector_seg
;Set up the interrupt vectors.
BEG: CLI ;Ensure no interrupt occurs.
MOV AX,VECTOR_SEG ;DS = vector_seg
MOV DS,AX
MOV IR0_IP_VECT,OFFSET ISR0 ;load all ISR's IP and CS
MOV IR1_IP_VECT,OFFSET ISR1
MOV AX,CS
MOV IR0_CS_VECT,AX
MOV IR1_CS_VECT,AX
ASSUME DS:DATA_SEG ;offset relative to data_seg
MOV AX,DATA_SEG ;Define data segment
MOV DS,AX
CALL INIT ;Initialization
STI ;Enable the interrupt now.
LOOP1: NOP
JMP LOOP1
CODE_SEG ENDS
;----------------------------------------------------------------------------
; S T A R T O F D A T A S E G M E N T
;----------------------------------------------------------------------------
DATA_SEG SEGMENT
DAC_MEMORY DB 0 ;Holds the current DAC value
GARBAGE DB 0 ;Holds the current garbage character.
LED_TABLE DB 3FH ;Display '0'
DB 06H ; '1'
DB 5BH ; '2'
DB 4FH ; '3'
DB 66H ; '4'
DB 6DH ; '5'
DB 7DH ; '6'
DB 07H ; '7'
DB 7FH ; '8'
DB 6FH ; '9'
DB 77H ; 'A'
DB 7CH ; 'B'
DB 39H ; 'C'
DB 5EH ; 'D'
DB 71H ; 'F'
DATA_SEG ENDS
END BEG
;******************************************************************************
; E N D O F P R O G R A M
;******************************************************************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment