pic单片机汇编程序翻译成c语言
高手帮忙把这段汇编翻译成c,小弟不胜感激!!!!!!!!!
list p=16f877;
#include <p16f877.inc>
xmit_data equ 30h
data_cnt equ 31h
ccpi_int_cnt equ 32h
org 000h
reset
goto start
org 0004h
;;;;;;;;;;;;;;;;;;;;;;;;;;;ccp中断
PER_INT_V
BCF STATUS,RP0;
BCF PIR1,CCP1IF;
INCF ccpi_int_cnt,F;
BTFSS ccpi_int_cnt,0;
GOTO SYNC_PULSE
DATA_PULSE
DECF data_cnt,F;
BTFSC STATUS,Z
goto PERIOD_DELTA
RLF xmit_data,F;
MOVLW 5EH;
BTFSC STATUS,C;
MOVLW 2FH;
SEND_DATA;发送
ADDWF CCPR1L,F;
BTFSC STATUS,C;
INCF CCPR1H,F;
GOTO RET_FIE;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;发送结尾
PERIOD_DELTA
MOVLW 0EEH;
ADDWF CCPR1L,F;
BTFSC STATUS,C
INCF CCPR1H,F;
MOVLW 2;
ADDWF CCPR1H,F;
RET_FIE
BCF CCP1CON,0;
RETFIE;中断返回
SYNC_PULSE
MOVLW 2FH;
ADDWF CCPR1L,F;
BTFSC STATUS,C;
INCF CCPR1H,F;
BSF CCP1CON,0;
RETFIE;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN()
start
bcf STATUS,RP1;
bcf STATUS,RP0;
CLRF TMR1H
CLRF TMR1L
;MOVLW 0XFF;
;MOVWF TMR1H;
;MOVLW 0XFF;
;MOVWF TMR1L;
CLRF INTCON
CLRF PIR1
CLRF PIR2
BSF STATUS,RP0
MOVLW 0x00;
MOVWF OPTION_REG
CLRF PIE1;
CLRF PIE2;
CLRF T1CON
MOVLW 0xff;
MOVWF TRISB;
MOVLW B'11111011'
MOVWF TRISC;
BSF PIE1,CCP1IE;
BCF STATUS,RP0;
BSF INTCON,PEIE;
BSF INTCON,GIE;
MOVLW 0x08;
MOVWF CCP1CON;
MOVLW 0x09;
MOVWF data_cnt;
MOVLW 0xff;
MOVWF ccpi_int_cnt;
BSF T1CON,TMR1ON;
NEXT_BYTE
WAIT
MOVF data_cnt,w;
BTFSS STATUS,Z
GOTO WAIT;
MOVF PORTB,W;
MOVWF xmit_data;
MOVLW 0xff;
MOVWF ccpi_int_cnt;
MOVLW 0x09;
MOVWF data_cnt;
GOTO NEXT_BYTE;
end;
[解决办法]
测试f 中的某位,为1 则跳过下一句
[解决办法]
WAIT 这是标号
MOVF data_cnt,w;取变量data_cnt到W寄存器
BTFSS STATUS,Z 因为上次操作影响状态寄存器的Z位,判断Z位是否为1,是则跳过goto语句,否则执行goto语句
GOTO WAIT;
看来data_cnt你声明了volatile类型,这段语句相当于while(data_cnt != 0);
你是对的。
[解决办法]
自己查指令表吧,能用C的谁会去记这些指令!
[解决办法]
指令早就不记得了,pic很简单,一共好像就二三十条指令,看看就懂了。
[解决办法]
LIST P=16F877; #INCLUDE <P16F877.INC> XMIT_DATA EQU 30H DATA_CNT EQU 31H CCPI_INT_CNT EQU 32H ORG 000H RESET GOTO START ORG 0004H ;;;;;;;;;;;;;;;;;;;;;;;;;;;CCP???PER_INT_V BCF STATUS,RP0; ;bank(0) BCF PIR1,CCP1IF; ;CCP1IF=0; INCF CCPI_INT_CNT,F; ;CCPI_INT_CNT++ BTFSS CCPI_INT_CNT,0; ;if(CCPI_INT_CNT%2=1){ GOTO SYNC_PULSEDATA_PULSE DECF DATA_CNT,F; DATA_CNT--; BTFSC STATUS,Z if(DATA_CNT!=0){ GOTO PERIOD_DELTA RLF XMIT_DATA,F; if(XMIT_DATA/128==1) CCPR1+=0x2F; MOVLW 5EH; else CCPR1+=0x5E; BTFSC STATUS,C; XMIT_DATA*=2; MOVLW 2FH;SEND_DATA;??E ADDWF CCPR1L,F; BTFSC STATUS,C; INCF CCPR1H,F; GOTO RET_FIE; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;??E???PERIOD_DELTA MOVLW 0EEH; ADDWF CCPR1L,F; BTFSC STATUS,C INCF CCPR1H,F; MOVLW 2; ADDWF CCPR1H,F;RET_FIE BCF CCP1CON,0; ;CCP1CON.ON=0 RETFIE;??????^ }else{ SYNC_PULSE MOVLW 2FH; ADDWF CCPR1L,F; ;CCPR1+=0x2F BTFSC STATUS,C; INCF CCPR1H,F; BSF CCP1CON,0; ;CCP1CON.ON=1 RETFIE; } ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAIN()START: BCF STATUS,RP1; BCF STATUS,RP0; ;BANK(0) CLRF TMR1H CLRF TMR1L ;TMR1=0 ;MOVLW 0XFF; ;MOVWF TMR1H; ;MOVLW 0XFF; ;MOVWF TMR1L; CLRF INTCON ;INTCON =0 CLRF PIR1 ;PIR1=0 CLRF PIR2 ;PIR2=0 BSF STATUS,RP0 ;BANK(1) MOVLW 0X00; MOVWF OPTION_REG ;OPTION_REG =0; CLRF PIE1; ;PIE1=0 CLRF PIE2; ;PIE2=0 CLRF T1CON ;T1CON=0 MOVLW 0XFF; MOVWF TRISB; ;TRISB=0xFF MOVLW B'11111011' MOVWF TRISC; ;TRISC=0XFB BSF PIE1,CCP1IE; ;CCP1IE =1 BCF STATUS,RP0; ;BANK(0) BSF INTCON,PEIE; ;PIEE=1 BSF INTCON,GIE; ;GIE =1 MOVLW 0X08; MOVWF CCP1CON; ;CCP1CON =8 MOVLW 0X09; MOVWF DATA_CNT; ;DATA_CNT =9 MOVLW 0XFF; MOVWF CCPI_INT_CNT; ;CCP1_INT_CNT =0xFF BSF T1CON,TMR1ON; ;TMR1ON =1 NEXT_BYTE ;while(1){ WAIT MOVF DATA_CNT,W; ; if(DATA_CNT)wait(); BTFSS STATUS,Z GOTO WAIT; MOVF PORTB,W; MOVWF XMIT_DATA; ; XMIT_DATA=PORTB; MOVLW 0XFF; MOVWF CCPI_INT_CNT; ; CCPI_INT_CNT=0xFF MOVLW 0X09; MOVWF DATA_CNT; ; DATA_CNT=0x09 GOTO NEXT_BYTE; }