最近又再接pic的小项目了,但是在串口输出到电脑的时候,总是出问题,在这里我首先确认一下软件商是否有问题,代码如下:下面是main函数
- int main()
- {
- initial(); //System initialization on PIC MCU
- introduction();
- while(1)
- {
- //operation();
- if(comsendFlag == 1)
- {
- ComDataSendMessage();
- comsendFlag = 0;
- }
-
- }
- return 0;
- }
中断函数:
- //Interrupt Period
- void interrupt ISR(void)
- {
- if (T0IE && T0IF) //10ms判TMR0 中断
- {
- TMR0=0X28; //******TMR0 中断服务*****10MS
- T0IF = 0; //清除TMR0 中断标志
- //send signal every 1 sec
- comsendCount++;
- if(comsendCount > TIME_SECOND_ONE) //reach to 1 sec
- {
- comsendCount = 0;
- //if(comsendFlag == 0)
- comsendFlag = 1;
- }
- }
- }
初始化函数:
- void initial()
- {
- PORTA=0x00; //Clear I/O port
- PORTB=0x00;
- PORTC=0x00;
- CMCON=0x07; //shutoff comparision
- ADCON1=0x00; //set A/D:all ANx ANALOG IN
- TRISA=0x3F; //RA0 RA1 RA2 RA3 RA4 RA5 ANALOG IN 0011 1111
- TRISB=0x20; //RB5 DATA IN ,others D/O 0010 0000
- TRISC=0x00; //0000 0000
- PORTA=0x00;
- PORTB=0x00;
- PORTC=0x00; //Clear I/O port
- //PR2=24;
- // CCP1CON=0x0f;
- // CCPR1L=0x00; //0%
- //
- // CCP2CON=0x0f;
- // CCPR2L=0x00; //0%
- //
- // T2CON=0x04; //start time2 and prescaler 1:1
- /****Timer0 SET**************************************************************/
- OPTION=0x86; //time0 1:128
- TMR0=0X16;
- //Serial initial
- TXSTA = 0x04; //chose ASYNC high speed 8bit, 0x0000 0100
- RCSTA = 0x80; //enable, 0x1000 0000
- TRISC = TRISC|0x80; //set TRISC<7>:RC7 input
- TRISC = TRISC&0xBF; //set TRISC<6>:RC6 output
- SPBRG = 71; //11.0592MHz,9600
- PIR1 = 0x00; //clear interrupt flag
- PIE1 = PIE1|0x20;
- //PIE1 |=
- CREN = 1;
- SSPEN = 0;
- GIE=1;
- T0IE=1;
- }
看了看pic16f873a的手册,感觉没问题啊,不知怎么回事,超级终端里输出的总是不理想,哪位大侠能否指点一下啊,谢谢啊!
|