研究生
最后登录1970-1-1
在线时间 小时
注册时间2016-6-14
|
#include "p30f5011.h"
#include "uart.h"
#include "B61509V.h"
_FOSC(CSW_FSCM_OFF & XT_PLL8);
_FWDT(WDT_OFF);
_FBORPOR(MCLR_EN & PBOR_OFF);
_FGS(CODE_PROT_OFF);
unsigned int temp=0,Lowarm=100,an_cnt=0,t_cnt=0,cnt=0,cnt1=0,cnt2=0;
unsigned char intens=1,m_intens=0,f_intens=0,ff_intens=0,in=7,et=0x44,flag_1=0,zb_flag=0;
unsigned int shuzhi=0,f_shuzhi=0,ff_shuzhi=0,m_shuzhi=0;
unsigned int speakTime=0;//xujj
unsigned char lowArmFlag=0;//显示函数标志
int main (void);
void initINT();//xujj
void Uart2int(void);
void Uart1int(void);
void INIT(void);
void initPWM();
int main(void)
{
INIT();
TFT_Initial();
intdisplay();
LATCbits.LATC13 = 0;
Uart1int();
Uart2int();
while(1)
{
if(flag_1==1)
{
flag_1=0;
if(shuzhi>=Lowarm)
{
LATCbits.LATC13 = 1;
}
else
LATCbits.LATC13 = 0;
LCD_PutString_shuzi(shuzhi,White,Black);
LowArm_display(Lowarm);
delay(200);
U1MODEbits.UARTEN = 1;
IEC0bits.U1RXIE = 1;
IFS0bits.U1RXIF = 0;
U2MODEbits.UARTEN = 1;
IEC1bits.U2RXIE = 1;
IFS1bits.U2RXIF = 0;
}
}
}
void INIT(void)
{
TRISB = 0;
TRISC = 0x00;
TRISD = 0x0f00;
TRISF = 0x14;
TRISG = 0;
LATGbits.LATG3 = 1;
LATCbits.LATC13 = 1;
LATCbits.LATC14 = 1;
_LATD6 = 0;
_LATD7 = 1;
_LATD0 = 1;
_LATF6 = 0;
}
void Uart1int(void)/////串口1
{
U1BRG = 143;
IPC2bits.U1RXIP = 2;
U1STA = 0x0000;
U1MODE = 0x8000;
IEC0bits.U1RXIE = 1;
IEC0bits.U1TXIE = 0;
IFS0bits.U1RXIF = 0;
IFS0bits.U1TXIF = 0;
INTCON1 = 0X0000;
}
void Uart2int(void)/////串口2
{
IPC6bits.U2RXIP = 3;
U2STA = 0x0000;
U2MODE = 0x8000;
IEC1bits.U2RXIE = 1;
IEC1bits.U2TXIE = 0;
IFS1bits.U2RXIF = 0;
}
void initPWM()////定时器
{
unsigned int PW=1360;
T2CON=0x0010;//预分频比1:8
OC8RS=PW;
OC8CON=0x0006;//pwm 模式
TMR2=0;
PR2=PW*2;
T2CONbits.TON=1;//打开定时器
}
void __attribute__((__interrupt__,no_auto_psv)) _U1RXInterrupt(void)///串口通信 传输数据 动态显示
{
unsigned char cnt,rep_data[4];
IFS0bits.U1RXIF = 0;
if(U1RXREG == 0x88)
{
IEC0bits.U1RXIE = 0;
for(cnt=0;cnt<4;cnt++)
{
while(!U1STAbits.RIDLE);
rep_data[cnt] = U1RXREG;
}
flag_1=1;
shuzhi = rep_data[0]*256+rep_data[1];
intens = rep_data[2];
et = rep_data[3];
U1STAbits.UTXEN = 0;
U1MODEbits.UARTEN = 0;
}
}
void __attribute__((__interrupt__,no_auto_psv)) _U2RXInterrupt(void)
{
unsigned char rep_data=0;
// RXValue = U2RXREG;
IFS1bits.U2RXIF = 0;
if(U2RXREG == 0xFF)
{
IEC1bits.U2RXIE = 0;
while(!U2STAbits.RIDLE);
rep_data = U2RXREG;
if(rep_data==0x0D)
{
Lowarm+=10;
if(Lowarm >=1000)
Lowarm = 10;
}
if(rep_data==0x09)
{
Lowarm-=10;
if(Lowarm ==0)
Lowarm = 1000;
}
flag_1=1;
U2STAbits.UTXEN = 0;
U2MODEbits.UARTEN = 0;
}
}
/*外部中断初始化,利用外部中断检按键的电平变化*/
void initINT()
{
INTCON1 = 0x8000;
//外部中断负边沿,极性选择位
INTCON2 = 0x001f;
//外部中断允许位
// IEC1bits.INT1IE=1;
IEC1bits.INT2IE=1;
IEC2bits.INT3IE=1;
//复位外部中断标志位
IFS1bits.INT2IF=0;
IFS2bits.INT3IF=0;
IPC5bits.INT2IP = 5;
IPC9bits.INT3IP = 4;
}
void __attribute__((__interrupt__,no_auto_psv)) _INT2Interrupt( ) /////遥控器控制最低浓度的减
{
IFS1bits.INT2IF=0;
IEC1bits.INT2IE=0;
U2STAbits.UTXEN = 0;
U2MODEbits.UARTEN = 0;
delay(2000);
flag_1=0;
Lowarm-=10;
if(Lowarm ==0)
Lowarm = 10;
lowArmFlag=1;
while(!_RD9);
IEC1bits.INT2IE=1;
IFS1bits.INT2IF=0;
}
void __attribute__((__interrupt__,no_auto_psv)) _INT3Interrupt( )
{
IFS2bits.INT3IF=0;
IEC2bits.INT3IE=0;
U2STAbits.UTXEN = 0;
U2MODEbits.UARTEN = 0;
delay(2000);
flag_1=0;
Lowarm+=10;
lowArmFlag=1;
while(!_RD10);
IEC2bits.INT3IE=1;
IFS2bits.INT3IF=0;
}
|
|