;Displaying ATD0 channel 1 (POT) on 8 LEDs of PORTA for Freescale Project Board with HCS12 MCU module ;The HCS12 MCU Modules comes with USB-DBM and ready to be used with CodeWarrior IDE ;Modified from Program 13-1 of HCS12 textbook by Mazidi & Causey ;In HCS12 MCU Module XTAL=4MHz, Bus Freq. =2MHz. Then divivde it by 2 to get 1MHz for conversion freq. ;ATD0 channel 1 (AN01) is connected to POT. The POT is on the bottom corner left side of the Student Project Board. ;Change the POT to see the changes on LEDs of PORTA ;In HCS12 MCU Module RAM address is from $1000-3FFF ;We use RAM addresses starting at $1000 for scratch pad (variables) and $3FFF for Stack ;The lower 4 bits of PA3-PA0 are connected to LEDs(LED1-LED4 on J10) permanently ;and must be enabled by clearing bit P4 of PORTP. ;MAKE SURE both jumpers for LED and POT are set. LED and POT jumpers are part of group of jumpers called UFEA right next to the Buzzer ;To have 8 LEDs, we must also connect 4 wires from LED5-LED8 (J10) to pins PA7-PA4 via J6 connector ;Make sure you are in TBDML Mode before downloading ;Press F7 (to Make), then F5(Debug) to downLOAD,and F5 once more to start the program execution ABSENTRY Entry ; for absolute assembly: mark this as application entry point ; Include derivative-specific definitions INCLUDE 'mc9s12dt256.inc' ;CPU used by Axiom board ;----------------------USE $1000-$2FFF for Scratch Pad R1 EQU $1001 R2 EQU $1002 R3 EQU $1003 ;code section ORG $4000 ;Flash ROM address Entry: LDS #$4000 ;Stack LDAA #$FF STAA DDRA ;Make PA7-PA0 as output BSET DDRP, %00011000 ;Make PP3 and PP4 as output BCLR PTP, %00010000 ;Enable the LEDs by clearing bit P4 of PORTP ;to Have 8 LEDs, we need to connect 4 wires from LED5-LED8 to pins PA4-PA7 via J6 connector BSET PTP, %000001000 ;The POT is connected to AN01 (ADC0 chan 1) and must be enabled by setting high bit P3 of PORTP ; ;-------Get data fron Chan 1 of ATD0 and put it on LEDs of PORTA MOVB #$80,ATD0CTL2 JSR DELAY MOVB #$08,ATD0CTL3 MOVB #$E0,ATD0CTL4 ;8-bit resolu, 16-clock for 2nd phase, ;prescaler of 0 for Conversion Freq=1MHz H1 MOVB #$81,ATD0CTL5 ;Chan 1 of ATD0 H2 BRCLR ATD0STAT0,$80,H2 LDAA ATD0DR0L STAA PORTA JSR DELAY ;Optional BRA H1 ;Keep reading the ADC ;----------DELAY DELAY PSHA ;Save Reg A on Stack LDAA #10 ;Change this value to see STAA R3 ;how fast LEDs Toggle ;--10 msec delay. The Axiom board works with XTAL=4MHz ;Freq. for Instruction Clock Cycle is 2MHz (1/2 of 4MHz). ;(1/2MHz) x 10 Clk x100x20=10 msec. Overheads are excluded in this calculation. L3 LDAA #100 STAA R2 L2 LDAA #20 STAA R1 L1 NOP ;1 Intruction Clk Cycle NOP ;1 NOP ;1 DEC R1 ;4 BNE L1 ;3 DEC R2 ;Total Instr.Clk=10 BNE L2 DEC R3 BNE L3 ;-------------- PULA ;Restore Reg A RTS ;------------------- ;************************************************************** ;* Interrupt Vectors * ;************************************************************** ORG $FFFE DC.W Entry ;Reset Vector. CPU wakes here and it is sent to start of the code at $4000