经测试:通过; 写这个小程序,遇到了些小问题。解决后,便想记录下,以防后人重蹈覆辙。 // Created: Mar.5-2011 // By: eeorange /* * Crystall: 11.059MHz * Chip: AT89S52 */ #include <regx52.h> #include <stdio.h> #include <intrins.h> // 9600 8 N 1 void init_scom(){ EA = 0; // begin SCON = 0x50; // working in mode 1 PCON = 0x00; // SCOM = 0 ES = 1; // enable serial communication TI = 1; // scom transmission ready TH1 = 0xFD; // time 253(0xfd) TMOD = 0x20; // time mode 2(only use th1) TR1 = 1; // enable timer 1 EA = 1; // end } /* an example */ void put(unsigned char ch) { while(TI == 0); // while transfer is ready SBUF = ch; TI = 0; // start transfer } static void scom_itr() interrupt SIO_VECTOR{ if(TI){ // do nothing } if(RI){ RI = 0; // set reveived flag } } int main(){ init_scom(); P0_1 = 0; // just test if msc-51 is working. while(1){ _nop_(); put('a'); /* you can also use "printf("Hello/n"); " instead. */ } return 0; }