我把下面的程序放在主程序里怎么没反映呢,串口精灵没有输出字符啊!!!!
我用PIC18F248
loop movf count1,0 ;count1作为查表地址偏移量送入W
read1 ;字符串"my name"
addwf PCL,1 ;地址偏移量加当前PC值
retlw a'
' ;换行控制符号,即0DH=<CR>
retlw a'
' ;回车控制符号,即0AH=<LF>
retlw a'M' ;送回到微机超级终端的字符串
retlw a'y'
retlw a' '
retlw a'n'
retlw a'a'
retlw a'm'
retlw a'e'
retlw a'
'
retlw a'
' ;
retlw 0
movwf temp ;
GetData btfss PIR1,TXIF ;等待,直到USART空闲
goto GetData
movwf TXREG ;查表值送USART
incf count1,1 ;查表计数器加1
movf temp,W ;检查到读表值为"0"了吗
btfss STATUS,Z ;是!跳一步,结束查表
goto loop ;否!应该返回继续查表
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
1.PC机必须重启才能再次收到字符串(是双字符).
2.我再PORTB 7上接了个LED灯,
addwf PCL,1 ;地址偏移量加当前PC值
bsf PORTB,7
但是再次执行程序后灯不亮,应该是走到这步死机了,不知为何??
谢谢!!!!!!!!!
wow. I thought only a girly man would get killed by a simple program
here is software-uart, in C.
======uart-sw==================
void usart_putch(unsigned char ch)
{
unsigned char bitcount=1+8+1; //start bit, 8 data bits, 1 stop bit
//each
//RB4=0;
IO_CLR(USART_PORT, USART_Tx); //drive tx pin low - usart start condition
do {
usart_delay_tx_bit(); //delay some time
if (ch & 0x01) IO_SET(USART_PORT, USART_Tx); //send a 1
else IO_CLR(USART_PORT, USART_Tx); //otherwise, send a 0
ch=(ch>>1) | 0x80; //shift out the next bit
} while (--bitcount);
//NOP();
}
===========end=============
hardware uart is even simpler:
====uart-hw===========
void usart_putch(unsigned char ch)
{
//Wait for TXREG Buffer to become available
//while(!TXIF); //wait for prior transmission to finish
USART_WAIT(TXIF);
//Write data
TXREG=ch; //load up the tx register
//while(!TRMT); //wait for the transmission to finish
//don't use txif as this is not back-to-back transmission
}
============end================
; read1 ;字符串"my name" ?????
addwf PCL,1 ;地址偏移量加当前PC值
bsf PORTB,7 ;!!!!!不可在PCL运算中,count1=0时要错误的,
retlw a' ' ;换行控制符号,即0DH=<CR>
.
init232 .....
bcf TRISB,7 ;!!!!如设为输出,则不能用于RX接收
bcf TRISB,5
return
main
call init232
main2 call GetData
bsf PORTB,7 ;?? 如果需要
bsf PORTB,5 ;??
clrf count1 ;PCL运算从0开始
goto main2
end
;***Name:R485_tran_xx*********************
;***Function:发送一字节数据***************
;***IN:RS485_tran_temp********************
;***OUT:无********************************
;***USE:TXREG、RS485_tran_temp************
;*****************************************
R485_tran_xx
BSF RS485_EN
MOVFF RS485_tran_temp,TXREG1
TXW5 BTFSS TXSTA1,TRMT
GOTO TXW5
BSF RS485_TX
BCF RS485_EN
RETURN
一周热门 更多>