標題:
此文章來自奇摩知識+如有不便請留言告知
[8051]Serial Interrupt C prog.
發問:
我用緊89s51...想做serial interrupt...with RS232...serial transmission無問題...但係點都做唔到interrupt@@我寫既係c program...上網睇左好多source試極都無用...麻煩有無高手幫我睇睇~~~void serial_interrupt() interrupt 4{ while(1)LED=1;}void main( ) { SCON = 0x50; // setup serial port control TMOD = 0x20; //... 顯示更多 我用緊89s51...想做serial interrupt...with RS232... serial transmission無問題...但係點都做唔到interrupt@@ 我寫既係c program...上網睇左好多source試極都無用... 麻煩有無高手幫我睇睇~~~ void serial_interrupt() interrupt 4{ while(1) LED=1; } void main( ) { SCON = 0x50; // setup serial port control TMOD = 0x20; // hardware (9600 BAUD @11.05592MHZ) TH1 = 0xFD; // TH1 TR1=1; LED=0; while(1){} } 以上係超簡化版...但係work唔到... serial communicate做到....但係interrupt做唔到@@
最佳解答:
Polling or Interrupt Driven? When writing a communications program you have two methods available to you. You can poll the UART, to see if any new data is available or you can set up an interrupt handler to remove the data from the UART when it generates a interrupt. Polling the UART is a lot slower method, which is very CPU intensive thus can only have a maximum speed of around 34.8 KBPS before you start losing data. Some newer Pentium Pro's may be able to achieve better rates that this. The other option is using a Interrupt handler, and that's what we have used here. It will very easily support 115.2K BPS, even on low end computers. Termpoll.c - Simple Terminal Program using the Polling Method. Polling the UART should not be dismissed totally. It's a good method for diagnostics. If you have no idea of what address your card is at or what IRQ you are using you can poll the UART at several different addresses to firstly find which port your card is at and which one your modem is attached to. Once you know this information, then you can set up the Interrupt routines for the common IRQs and by enabling one IRQ at a time using the Programmable Interrupt Controller you can find out your IRQ, You don't even need a screw driver! Now, could we be off track just a little? Yes that's right, PORT1INT is the label to our interrupt handler called a Interrupt Service Routine (ISR). You can put just about anything in here you want. However calling some DOS routines can be a problem. void interrupt PORT1INT() { int c; do { c = inportb(PORT1 + 5); if (c & 1) { buffer[bufferin] = inportb(PORT1); bufferin++; if (bufferin == 1024) bufferin = 0; } } while (c & 1); outportb(0x20,0x20); } 睇下呢段資料幫5幫到你? 2009-04-05 17:20:22 補充: 加多幾個網址你睇: http://www.captain.at/programming/rtai/serportint.php, http://jiliweb.co.cc/8051/2009/89c2051-rs23/ 2009-04-05 18:14:29 補充: http://jiliweb.co.cc/8051/2009/89c2051-rs23/ 342-391行係interrupt 4寫法
其他解答:
不明白 void serial_interrupt() interrupt 4 的寫法, 但你可以詳細說明要用 interrupt 的目的為何.