我把下面的程序放在主程序里怎么没反映呢,串口精灵没有输出字符啊!!!!
我用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 ;否!应该返回继续查表
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
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================
一周热门 更多>