|

;This program read A/D ,AN0-AN4 and shows the reading on Hyper terminal ;=============================================================================; ; ; ; ;============================================================================== .equ __30F2010, 1 .include "p30f2010.inc" .include "serial_comm.inc" ;------------------------------------------------------------------------------ ;Global Declarations .global __reset ;The label for the first line of code .global __OscillatorFail ;Declare Oscillator Fail trap routine label .global __AddressError ;Declare Address Error trap routine label .global __StackError ;Declare Stack Error trap routine label .global __MathError ;Declare Math Error trap routine label ;------------------------------------------------------------------------------ ;Configuration bits config __FOSC, CSW_FSCM_ON & XT_PLL16 config __FWDT, WDT_OFF config __FBORPOR, PBOR_OFF & BORV_27 & PWRT_16 & MCLR_EN config __FGS, CODE_PROT_OFF .section .nbss, bss, near var0: .space 2 ;Example of allocating 1 word of space for var1: .space 2 var2: .space 2 var3: .space 2 ;variable "var1". suksun1: .space 2 ;suk ;------------------------------------------------------------------------------ ;Program Specific Constants (literals used in code) .equ FCY, #7372800 ;Instruction cycle rate (Osc x PLL / 4)
;============================================================================== ;Start of code .text ;Start of Code section ;------------------------------------------------------------------------------ ;Initialize stack pointer and limit register __reset: mov #__SP_init, W15 ;Initialize the Stack Pointer register mov #__SPLIM_init, W0 ;Get address at the end of stack space mov W0, SPLIM ;Load the Stack Pointer Limit register nop ;Add NOP to follow SPLIM initialization ;------------------------------------------------------------------------------ ;Initialize LED output on PORTB bit 0 mov #0xff00,W0 ;suk config PORTB<15:8> as inputs mov W0,TRISB ;suk config PORTB<7:0> as outputs mov #0xffff,W0 mov W0,TRISE ;suk Confic PORTE as inputs ;mov #0x0000,W0 ;mov W0,TRISC ;------------------------------------------------------------------------------ ;Initialize Timer1 for 1/1 second period /* clr T1CON ;Turn off Timer1 by clearing control register clr TMR1 ;Start Timer1 at zero mov #FCY/256/1,W0 ;Get period register value for 1/5 second mov W0, PR1 ;Load Timer1 period register mov #0x8030,W0 ;Get Timer1 settings (1:256 prescaler) mov W0, T1CON ;Load Timer1 settings into control register */ ;------------------------------------------------------------------------------ ;Initialize UART CALL Init_UART ; CALL _NewPage ;Initialize A/D MOV #0xFFF0,W0 ; #0xFFFE,W0 ; MOV W0,ADPCFG; MOV #0x0008,W0 ; #0x0000,W0; MOV W0,ADCON1; MOV #0x0003,W0 ; #0x0000,W0; MOV W0,ADCHS; MOV #0x0000,W0; MOV W0,ADCSSL; MOV #0x0082,W0; MOV W0,ADCON3; MOV #0x0200,W0 ; #0x0000,W0; MOV W0,ADCON2; BSET ADCON1,#ADON; MainLoop: ;btss U1STA,#URXDA ;bra MainLoop ;MOV U1RXREG,W7; ;mov W2,U1TXREG ;CALL _NewLine ;CALL SEND_ /* btss IFS0, #T1IF ;Check if Timer1 interrupt flag is set bra MainLoop ;Loop back until set bclr IFS0, #T1IF ;Clear Timer1 interrupt flag ;btg LATD, #0 */ ;Toggle LED BSET ADCON1,#SAMP; Call Delay ; BCLR ADCON1,#SAMP ; WAIT: BTSS ADCON1,#DONE ; BRA WAIT; MOV ADCBUF0,W1; MOV W1,var3; MOV ADCBUF1,W1; MOV W1,var0; MOV ADCBUF2,W1; MOV W1,var1; MOV ADCBUF3,W1; MOV W1,var2; ;CALL SEND_ ; ;CALL _Home ; ;MOV W1,W4 ;COM W4,W4 ;MOV W4,LATB ;btg LATB, #0 ;SUk ;btg LATC, #13 CALL Display ; ;INC W1,W1 ; bra MainLoop ;Loop back ;============================================================================== /* clr U1STA mov #0x8000,W0 ; enable UART module mov W0,U1MODE mov #BR,W0 ; set baudrate using formula value mov W0, U1BRG ; / bset U1STA,#UTXEN ; initiate transmission Again: rcall Delay500mSec ; delay for 500 mS mov #psvpage(hello),w0 mov w0, PSVPAG bset.b CORCONL,#PSV mov #psvoffset(hello),w0 TxSend: mov.b [w0++], w1 ; get char in string cp w1,#0 ; if Null bra Z,Again ; then re-initialize BufferTest: btsc U1STA,#UTXBF ; see if buffer full bra BufferTest ; wait till empty mov w1,U1TXREG ; load value in TX buffer bra TxSend ; repeat for next char. */
;============================================================================== ;Error traps ;------------------------------------------------------------------------------ ;Oscillator Fail Error trap routine .text ;Start of Code section __OscillatorFail: bclr LATD, #0 ;Turn LED on bra __OscillatorFail ;Loop forever when oscillator failure occurs ;------------------------------------------------------------------------------ ;Address Error trap routine __AddressError: bclr LATD, #0 ;Turn LED on bra __AddressError ;Loop forever when address error occurs ;------------------------------------------------------------------------------ ;Stack Error trap routine __StackError: bclr LATD, #0 ;Turn LED on bra __StackError ;Loop forever when stack error occurs ;------------------------------------------------------------------------------ ;Math (Arithmetic) Error trap routine __MathError: bclr LATD, #0 ;Turn LED on bra __MathError ;Loop forever when math error occurs ;============================================================================== Delay: mov #0x0001,w4 Again2: mov #0x0fff,W3 ; Again1: DEC W3,W3 ; BRA NZ, Again1 DEC W4,W4 BRA NZ, Again2 RETURN ;============================================================================= .end ;End of code in this file ; Code in "serial_comm.inc" file inculde file ; This include file set A/D and Serial port .equ baudrate,#47; #0x00bf; #191 ;suk Set baudrate .text Init_UART: ;Initialize UART CLR U1STA CLR U1MODE MOV #0x8000,W0 ; Enable UART for 8-bit data, ; no parity, 1 STOP bit, ; no wakeup MOV W0,U1MODE BSET U1MODE,#ALTIO MOV #baudrate,W0 ; Set Baudrate MOV W0,U1BRG ;BSET IPC2,#U1TXIP2 ; Set UART TX interrupt priority ;BCLR IPC2,#U1TXIP1 ; ;BCLR IPC2,#U1TXIP0 ; ;BSET IPC2,#U1RXIP2 ; Set UART RX interrupt priority ;BCLR IPC2,#U1RXIP1 ; ;BCLR IPC2,#U1RXIP0 ; BSET U1STA,#UTXEN ; Enable transmit ;BSET IEC0,#U1TXIE ; Enable transmit interrupts ;BSET IEC0,#U1RXIE ; Enable receive interrupts RETURN Display: CALL _Home CALL _NewLine CALL _Space CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'A',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'N',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'0',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV var0,W2; CALL SEND_ ; CALL _Tab CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'A',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'N',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'1',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV var1,W2; CALL SEND_ ; CALL _NewLine ; CALL _Return ; CALL _Space; CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'A',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'N',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'2',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV var2,W2; CALL SEND_ ; CALL _Tab CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'A',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'N',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'3',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV var3,W2; CALL SEND_ ; /* CALL _NewLine ; CALL _Return ; CALL _Space; CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'W',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'3',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV W1,W2; CALL SEND_ ; CALL _Tab CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'W',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'4',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV W1,W2; CALL SEND_ ; CALL _NewLine ; CALL _Return ; CALL _Space; CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'W',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'5',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV W1,W2; CALL SEND_ ; CALL _Tab CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'W',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'6',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #'=',W0 mov W0,U1TXREG CALL BufferTest ; wait till empty mov.b #' ',W0 mov W0,U1TXREG MOV W1,W2; CALL SEND_ ; */ RETURN ; SEND_: DO #3,END2 DO #3,END1 RLC W2,W2 BRA C, CARRY NO_C:
CALL BufferTest ; wait till empty mov.b #'0',W0 ;SNED '0' mov W0,U1TXREG GOTO END1 CARRY: CALL BufferTest mov.b #'1',W0 ;SEND '1' mov W0,U1TXREG NOP END1: NOP CALL BufferTest; wait till empty mov.b #' ',W0 ;SEND '' mov W0,U1TXREG END2: NOP RETURN BufferTest: btsc U1STA,#UTXBF ; see if buffer full bra BufferTest ; wait till empty RETURN _NewPage: CALL BufferTest ; wait till empty mov.b #0x0C,W0 ;New page =0x0C mov W0,U1TXREG RETURN _NewLine: CALL BufferTest ; wait till empty mov.b #0x0A,W0 ; New Line =0x0A mov W0,U1TXREG ; RETURN _Return: CALL BufferTest ; wait till empty mov.b #0x0D,W0 ; Return =0x0D mov W0,U1TXREG ; RETURN _Space: CALL BufferTest ; wait till empty mov.b #0x20,W0 ; Space=0x20 mov W0,U1TXREG RETURN _Tab: CALL BufferTest ; wait till empty mov.b #0x09,W0 ; Horizontal Tab =0x09 mov W0,U1TXREG ; RETURN _Home: CALL BufferTest ; wait till empty mov.b #0x1B,W0 ; mov W0,U1TXREG ; CALL BufferTest ; wait till empty mov.b #0x5B,W0 ; mov W0,U1TXREG ; CALL BufferTest ; wait till empty mov.b #0x48,W0 ; mov W0,U1TXREG ; RETURN
|