Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

assembly code for input 256kbps bitstream

Status
Not open for further replies.

ceibawx

Junior Member level 2
Joined
Oct 13, 2008
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
chongqing,China
Activity points
1,606
Hi your help is needed.
input clock is 256khz, input bit data is 256kbps.20MHz is oscillator frequency for PIC16F877.
Why it doesn't pass compiling.
How to record bitdata in PIC?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

MOVLW 0x08
MOVWF BitCounter ;bitcounter=8
MOVLW 0x0A
MOVWF ByteCounter ;bytecounter=9
MOVLW 0x00
MOVWF Data[ByteCounter] ;data[9]=0

; collect bit data on the rising edge.
;C0 IS CLOCK INPUT
;C1 IS BIT DATA INPUT
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Wait_To_1: BTFSS PORTC, 0 ; CLOCK value judge
goto Wait_To_1 ;CLOCK=0;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CLOCK=1
RLF Data[ByteCounter]
; one clock comes, Data[ByteCounter] left shift,input bit data is stored into Data[ByteCounter]
BTFSC PORTC, 1 ;DATA VALUE
DECF Data[ByteCounter],1 ; or "NOP" ;DATA=0, SIKP
INCF Data[ByteCounter],1 ;DATA=1

Wait_To_0: BTFSC PORTC, 0
goto Wait_To_0 ;CLOCK=1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CLOCK=0

DECFSZ BitCounter, 1
;after decrease 1, if BitCounter value=0,then skip"goto Wait_To_1", to do"MOVLW 0x08, MOVWF BitCounter, DECFSZ ByteCounter, 1…". another data is stored.
goto Wait_To_1
MOVLW 0x08
MOVWF BitCounter ;bitcounter value=8;
DECFSZ ByteCounter, 1 ; ByteCounter decrease 1
;;;;;;;;;;after decrease 1, if ByteCounter value=0
goto NextByte ;ByteCounter = 1
goto TransData ;ByteCounter = 0

NextByte: MOVLW 0x00
MOVWF Data[ByteCounter]
goto Wait_To_1

TransData:

But when I added it to original assembly code. it doesn't work.
;********************************
list p=16f877 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions


; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF


;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving

;**********************************************************************
ORG 0x000 ; processor reset vector

nop
goto Main ; go to beginning of program
;**********************************************************************

ORG 0x004 ; interrupt vector location

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register

; isr code can go here or be located as a call subroutine elsewhere

movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt



Main:

banksel TRISC
bcf TRISC,6

; UART module setup
banksel SPBRG
movlw 9
movwf SPBRG ; Enable SPBRG register for 9600 Baud Rate//this is wrong.

banksel TXSTA ; Select memory bank for TXSTA SFR
movlw b'00101110' ; UART Asynchronous mode, 8-bit transmission, High Baud Rate
movwf TXSTA ; Enable Transmission

banksel RCSTA
movlw b'10010000' ; Enable 8-bit reception
movwf RCSTA

bsf RCSTA,SPEN ; Enable Serial port
bsf RCSTA,CREN ; Enable Receiver

;MainLoop:

banksel TXREG
movlw 0x55
movwf TXREG ; Move the data to the transmit register
; Once, the data is moved to the transmit register
; it will transmit by itself

MainLoop
banksel RCREG
movf RCREG,W
movwf TXREG

goto MainLoop


END ; directive 'end of program'

;*************************************************************

Any suggestion is appreciated.

Added after 1 hours 45 minutes:

Hey,
I got the output data.
but one question is there are two output.
sometimes it is 0101010101.
Sometimes it is 0010101001.
What's the problem?
Can you see it for me?

;**********************************************************************


list p=16f877 ; list directive to define processor
#include <p16f877.inc> ; processor specific variable definitions


; '__CONFIG' directive is used to embed configuration data within .asm file.
; The labels following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.

; __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _HS_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF

;C0 IS CLOCK INPUT
;C1 IS BIT DATA INPUT
;***** VARIABLE DEFINITIONS
w_temp EQU 0x7D ; variable used for context saving
status_temp EQU 0x7E ; variable used for context saving
pclath_temp EQU 0x7F ; variable used for context saving
BitCounter EQU 0xBD ;vairable used for input bit data saving
ByteCounter EQU 0x3E ;vairable used for input bit data saving
bitData EQU 0xBF ;vairable used for input bit data saving
;**********************************************************************
ORG 0x000 ; processor reset vector

nop
goto Main ; go to beginning of program
;**********************************************************************

ORG 0x004 ; interrupt vector location

movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register

; isr code can go here or be located as a call subroutine elsewhere

movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt



Main:

banksel TRISC
bcf TRISC,6

; UART module setup
banksel SPBRG
movlw 9
movwf SPBRG ; Enable SPBRG register for 9600 Baud Rate//this is wrong.

banksel TXSTA ; Select memory bank for TXSTA SFR
movlw b'00101110' ; UART Asynchronous mode, 8-bit transmission, High Baud Rate
movwf TXSTA ; Enable Transmission

banksel RCSTA
movlw b'10010000' ; Enable 8-bit reception
movwf RCSTA

bsf RCSTA,SPEN ; Enable Serial port
bsf RCSTA,CREN ; Enable Receiver

;recorddata
MOVLW 0x08
MOVWF BitCounter ;bitcounter=8
MOVLW 0x0A
MOVWF ByteCounter ;bytecounter=9
MOVLW 0x00
MOVWF bitData;[ByteCounter] ;bitdata[]=0

; collect bit data on the rising edge.

;*******************************************************************
Wait_To_1: BTFSS PORTC, 0 ; CLOCK value judge
goto Wait_To_1 ;CLOCK=0;
;****************************************************************CLOCK=1
RLF bitData;[ByteCounter]
; one clock comes, Data[ByteCounter] left shift,input bit data is stored into Data[ByteCounter]
BTFSC PORTC, 1 ;DATA VALUE
DECF bitData,1;[ByteCounter],1 ; or "NOP" ;DATA=0, SIKP
INCF bitData,1;[ByteCounter],1 ;DATA=1
Wait_To_0: BTFSC PORTC, 0
goto Wait_To_0 ;CLOCK=1
;****************************************************************CLOCK=0
DECFSZ BitCounter, 1
;after decrease 1, if BitCounter value=0,then skip"goto Wait_To_1", to do"MOVLW 0x08, MOVWF BitCounter, DECFSZ ByteCounter, 1…". another data is stored.

goto Wait_To_1
MOVLW 0x08
MOVWF BitCounter ;bitcounter value=8;
DECFSZ ByteCounter, 1 ; ByteCounter decrease 1

;;;;;;;;;;after decrease 1, if ByteCounter value=0
goto NextByte ;ByteCounter = 1
goto TransData ;ByteCounter = 0

NextByte: MOVLW 0x00
MOVWF bitData;[ByteCounter]
goto Wait_To_1



TransData:
;MainLoop:

banksel TXREG
;movlw 0x55
movf bitData,W
;movlw bitData
movwf TXREG ; Move the data to the transmit register
; Once, the data is moved to the transmit register
; it will transmit by itself
;MainLoop
;banksel RCREG
;movf RCREG,W
;movwf TXREG
;goto MainLoop
goto TransData
END ; directive 'end of program'

;*********************************************************************************************************************************************
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top