;----------------------------------------------------------------------------- ; 4/26/2006 sjd ; ; ; ; FILE NAME : ADC1.ASM ; TARGET MCU : C8051F120 ; DESCRIPTION : This program illustrates how to configure the ; : ADC1 and Crossbar, read the ADC1 and write to the ; : port 2 & 3 I/O pins. ; : LED displays used as indicators. ; ; ; NOTES: ; ; (1) This note intentionally left blank. ; ; ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; EQUATES ;----------------------------------------------------------------------------- $include (c8051f120.inc) ; Include register definition file. ;----------------------------------------------------------------------------- ; VARIABLES ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; RESET and INTERRUPT VECTORS ;----------------------------------------------------------------------------- ; Reset Vector cseg AT 0 ljmp Main ; Locate a jump to the start of code at ; the reset vector. ;----------------------------------------------------------------------------- ; CODE SEGMENT ;----------------------------------------------------------------------------- Code_Seg segment CODE rseg Code_Seg ; Switch to this code segment. using 0 ; Specify register bank for the following ; program code. ; Set SFRPAGE to LEGACY_PAGE before writing to REF0CN Main: mov SFRPAGE, #LEGACY_PAGE ; Enable Vref - required before using adc mov REF0CN, #00000011b ; bias on, int vref. mov R0, #0 ;clear R0 mov R1, #0 ;clear R1 ; Use SFRs on Configuration Page mov SFRPAGE, #CONFIG_PAGE ; Enable the Port I/O Crossbar mov XBR2, #40h ; P2, P3 set for output to LED displays. mov P2, R0 mov P3, R1 ; Use SFRs on ADC0_PAGE mov SFRPAGE, #ADC0_PAGE ;loop. mov AMX0SL, #00000001b ; select adc1 Loop: mov ADC0CN, #10010000b mov R0, ADC0H mov R1, ADC0L mov P2, R0 ; write ADC0H value to port2 mov P3, R1 ; write ADC0L value to port3 jmp Loop ;----------------------------------------------------------------------------- ; End of file. END