INCLUDE 89C51.MC ;---------------------------------------------------------- ; Microcontroller connections to ADC0808/9 lines. CONTROL EQU P3 ; All control signals ADD_A EQU P3.0 ; Pin 25 ADD A ADD_B EQU P3.1 ; Pin 24 ADD B ADD_C EQU P3.2 ; Pin 23 ADD C START EQU P3.3 ; Pin 6 Start EOC EQU P3.4 ; Pin 7 EOC OE EQU P3.5 ; Pin 9 Output Enable ALE EQU P3.6 ; Pin 22 ALE DATA EQU P1 ; Data Lines ;---------------------------------------------------------- ; Register definitions. ADDRESS EQU 00h ; Address pointer BUFFER EQU 01h ; Data register ;---------------------------------------------------------- on_reset: ;Initialize ADC MOV CONTROL,#00H ; Make all control signals low MOV DATA,#FFH ; Data lines for input MOV ADDRESS,#02H ; Analog channel address CALL read_adc ; Get Adc data for given channel in A MOV A,BUFFER ; Data in acc ENDLESS: JMP ENDLESS ;---------------------------------------------------------- read_adc: ; Read one byte of data from adc. ; Performs a analog conversion cycle. ; address of channel in register "ADDRESS", ; Returns data in BUFFER ; Destroys A. CLR OE ; Disable output MOV A,ADDRESS ANL A,#07H ANL CONTROL,#F8H ORL CONTROL,A ; Send address of analog channel SETB ALE ; Latch the address NOP NOP SETB START ; Start the conversion NOP CLR ALE NOP NOP CLR START NOP NOP EOCLOOP: JNB EOC, EOCLOOP ; Do until EOC high SETB OE ; Output Enable MOV BUFFER,DATA ; Get data in buffer RET ;---------------------------------------------------------