11111 - ASM Assembly Systems | ASM Assembly Systems GmbH ...
USB Code Test wrtitten in asm
Transcript of USB Code Test wrtitten in asm
-
8/13/2019 USB Code Test wrtitten in asm
1/6
;**********************************************************************; *; Filename: USB_Code_test.asm *; Date: 15th April 2006 *; File Version: 1.0 *; *; Author: Ian Stedman *; Company: *; *; *;**********************************************************************; *; Files required: *; *; *; *;**********************************************************************; *; Notes: *; A simple program to test the PIC16F877 to FTDI USB interface. *; It sends 'walking bit codes that are used to verify that there *; Are no stuck bits or solder shorts between pins.; *; *
;**********************************************************************
list p=16f877 ; list directive to define processor#include ; processor specific variable definitions
__CONFIG _LVP_OFF & _CP_OFF & _WDT_OFF & _BODEN_ON & _PWRTE_OFF & _HS_OSC & _WRT_ENABLE_ON & _DEBUG_OFF & _CPD_OFF
; '__CONFIG' directive is used to embed configuration data within .asm file.; The lables following the directive are located in the respective .inc file.; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONSw_temp EQU 0x40 ; variable used for context savingstatus_temp EQU 0x42 ; variable used for context savingadcresult EQU 0x44 ; ADC conversion resultusbdatarx EQU 0x46 ; Byte received from USB portusbdatatx EQU 0x48 ; Byte to send via USBcount EQU 0x50temp EQU 0x52time EQU 0x54READBIT EQU 0 ; PORT C Read bit to USBWRITEBIT EQU 1 ; PORT C Write bit to USBTXFULL EQU 2 ; PORT C TX Full input from US
BRXFULL EQU 3 ; PORT C RX Full input from USBINPORT EQU 255 ; Sets an I/O port as all inputsOUTPORT EQU 0 ; Seta an I/O port as all outputs
;**********************************************************************ORG 0x000 ; processor reset vectorclrf PCLATH ; ensure page bits are cleared
-
8/13/2019 USB Code Test wrtitten in asm
2/6
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector locationmovwf w_temp ; save off current W register contentsmovf STATUS,w ; move status register into W registermovwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS registermovwf STATUS ; restore pre-isr STATUS register cont
entsswapf w_temp,fswapf w_temp,w ; restore pre-isr W register contentsretfie ; return from interrupt
main call picinitmainloop call usbrecv
call display
movlw 20movwf timecall delay
; Start of the test code. The idea is to turn on each data bit individually, giving 32 codes for the 8 bit interface
movlw h'00'movwf usbdatatxcall usbsendmovlw h'01'movwf usbdatatxcall usbsendmovlw h'02'movwf usbdatatx
call usbsendmovlw h'03'movwf usbdatatxcall usbsendmovlw h'04'movwf usbdatatxcall usbsendmovlw h'05'movwf usbdatatxcall usbsendmovlw h'06'movwf usbdatatxcall usbsend
movlw h'07'movwf usbdatatxcall usbsendmovlw h'08'movwf usbdatatxcall usbsendmovlw h'09'movwf usbdatatxcall usbsendmovlw h'0A'
-
8/13/2019 USB Code Test wrtitten in asm
3/6
movwf usbdatatxcall usbsendmovlw h'0B'movwf usbdatatxcall usbsendmovlw h'0C'movwf usbdatatxcall usbsendmovlw h'0D'movwf usbdatatxcall usbsendmovlw h'0E'movwf usbdatatxcall usbsendmovlw h'0F'movwf usbdatatxcall usbsendmovlw h'10'movwf usbdatatxcall usbsendmovlw h'20'movwf usbdatatxcall usbsendmovlw h'30'
movwf usbdatatxcall usbsendmovlw h'40'movwf usbdatatxcall usbsendmovlw h'50'movwf usbdatatxcall usbsendmovlw h'60'movwf usbdatatxcall usbsendmovlw h'70'movwf usbdatatx
call usbsendmovlw h'80'movwf usbdatatxcall usbsendmovlw h'90'movwf usbdatatxcall usbsendmovlw h'A0'movwf usbdatatxcall usbsendmovlw h'B0'movwf usbdatatxcall usbsend
movlw h'C0'movwf usbdatatxcall usbsendmovlw h'D0'movwf usbdatatxcall usbsendmovlw h'E0'movwf usbdatatxcall usbsendmovlw h'F0'
-
8/13/2019 USB Code Test wrtitten in asm
4/6
movwf usbdatatxcall usbsendmovlw h'00'movwf usbdatatxcall usbsend
goto mainloop
; remaining code goes here
picinitbanksel OPTION_REGmovlw H'07'movwf OPTION_REG ; Set TMR0 to divide internal cl
ock by 256banksel TRISB
movlw OUTPORT movwf TRISB ;portb [7-0] outputs
movwf TRISA ;porta [7-0] outputsmovlw H'0C' ;setup portc [2-3] inputs [0-1,4
-7] outputsmovwf TRISC
movlw INPORT ;setup portd as inputs for now (USB port)movwf TRISDclrf ADCON1 ;left justified, all inputs a/d
bcf STATUS,RP0 ;bank 0movlw H'FF'movwf PORTC ; Ensure Ouputs are 1 (no read/w
rite)clrf PORTB ; All LEDs off.clrf PORTA
movlw B'01000001' ;Fosc/8 [7-6], A/D ch0 [5-3], a/d on [0] movwf ADCON0
bsf PORTC,6 ; Debug
return
; At the moment a simple function to output the received USB value to the 8 LEDson Port B
displaymovf usbdatarx,W ; Recall received databcf PORTC,7movf usbdatarx,Wmovwf PORTB ; Output it, job done!bsf PORTC,7bsf PORTC,6bsf PORTC,5
return
; A function to check for data received from the USB interface and if present, read it.; USB is on port D, RC0=READ, RC3=RX_Flagusbrecv
btfsc PORTC,RXFULL ; See if RX_flag = 0 which indicates there is data in the FIFO
retlw 0 ; return 0 for no data;If we got here there is data to read. Set PORT D = Input, READ=
-
8/13/2019 USB Code Test wrtitten in asm
5/6
High, wait, READ=Low then read port Dbanksel TRISDmovlw INPORTmovwf TRISD ; PORT D now input, safe to star
t the read access.banksel PORTDbsf PORTC,READBITnopnopbcf PORTC,READBIT ; READ now active LOW so READ po
rt Dnopnopmovf PORTD,Wmovwf usbdatarxbsf PORTC,READBIT ; Set RD = higreturn
; A function to send a byte of information via the USB interface. Checks the TXFflag prior to sending.; USB is on port D, RC1=Write, RC2=TX_Flag; The data to send will be in usbdatatx
usbsend movf PORTC,W ; Read in PORT C for debugbtfsc PORTC,TXFULL ; See if TX_Flag = 0 which indicates OK
to transmit.retlw 0 ; Return with 0 if full
how????;If we get here we can transmit. Set PORT D = output, WRITE=High
, Wait, WRITE=Low then Write Data, Write=Highbanksel TRISDmovlw OUTPORTmovwf TRISD ; PORT D now outputbanksel PORTDbsf PORTC,WRITEBIT ; Make sure WR is high before dat
a output. movf usbdatatx,Wmovwf PORTDnopbcf PORTC,WRITEBIT ; Write now activenopbsf PORTC,WRITEBIT ; All done, WR = high.
; Now tristate the databus, set PORT D to input.banksel TRISDmovlw INPORTmovwf TRISD ; PORT D now inputbanksel PORTD ; Return to page 0nop
return
;*******************************************************************; DELAY Subroutine. This routine provides a 1 second delay. Call for; as long as you want by storing your desired delay in 'time' before; calling.; EXAMPLE; movlw 10 ; The value here determines the time delay in seconds.; movwf time ; Store the value.; call delay ; call the delay routine.
-
8/13/2019 USB Code Test wrtitten in asm
6/6
;
delay call delay1 ; these lines make sure that the 1 second loop executes ntimes.
decfsz timegoto delayreturn ; When time is up, return from subroutine.
delay1 ; The code here initialise the RTCC.bsf STATUS,RP0movlw 0x07 ; For use by RTCC, prescaler was /256 or 0x07movwf OPTION_REG ; dittobcf STATUS,RP0clrf TMR0movlw 0x0e ; Delay time value for 1 secondmovwf count ; store the valuemovwf temp
sloop ; What follows is the actual delay loop for 1 second. btfsc TMR0,5 ; Reset the RTCC, wait for TMR0 bit 5 to go hich
goto jmp1goto sloop
jmp1 clrf TMR0 ; RTCC is cleared so decrement the count & repeat.
decfsz countgoto sloopwlooplo decfsz temp,F
goto wlooploreturn
END ; directive 'end of program'