Home > other >  Emergency!!!!!! Is originally want to T0 timer output PWM wave, timer T1 as baud rate, but two at th
Emergency!!!!!! Is originally want to T0 timer output PWM wave, timer T1 as baud rate, but two at th

Time:09-25

 # include "reg51. H" 
# include "intrins. H"
# include "music. H"
//# define uchar unsigned char
//# define uint unsigned int
Sbit ADCRD=P3 ^ 7;//define ADC0804 RD port
Sbit ADCWD=P3 ^ 6;//define ADC0804 WD port
Sbit xuantong=P2 ^ 0;//strobe ADC0804 control foot
Sbit led=P2 ^ 1;
Sbit INTR=P3 ^ 2;
INT8U Data;
INT8U time;
INT8U PWM.
INT8U flag1=0;
INT8U flag2=0;
INT8U flag3=0;
# define Time_init 78
//void delayms (INT8U x)
//{
//INT8U I, j;
//for (I=x; i> 0; I -)
//for (j=110; J> 0; J -);
//}
Void ADC_init ()
{
ADCWD=1;
_nop_();
ADCWD=0;//start A/D conversion
_nop_();
ADCWD=1;
_nop_();
//delayms (2000);//start later, leave more time for AD conversion
//P1=0 XFF;//read digital signal when the P1 mouth first buy 1
//ADCRD=1;
//_nop_ ();
//ADCRD=0;//A/D reading can make
//_nop_ ();
//Data=https://bbs.csdn.net/topics/P1;
}
Void Timer0Init ()
{
TMOD |=0 x20;//for timer 0 mode choice, work mode 0, only open the startup with TR0,
//IP=0 x10;
//TMOD |=0 x20;//set the T1 to baud rate generator
SCON=0 x50;//0101000 0 8 bits of data, and white parity
PCON=0 x00;//PCON=0;
TH1=256 - (OSC_FREQ COMM_BAUD_RATE/32/12);//set to 9600 baud rate
TL1=256 - (OSC_FREQ COMM_BAUD_RATE/32/12);
TR1=1;//open the timer 1
REN=1;//serial port 1 received enabled
ES=1;//serial port interrupts enabled
1
TH0=(8192 - Time_init)/32;//initialization time
TL0=(8192 - Time_init) % 32;//
ET0=1;//open the timer 0 interruption allows
EA=1;//open the total interruption
TR0=1;//open the timer
}
Void Timer0 () interrupt 1
{
TH0=(8192 - Time_init)/32;//to assignment
TL0=(8192 - Time_init) % 32;
time++;
If (time==100)//
Time=0;
Else if (time<=PWM)
{
Led=1;
}
The else
Led=0;
}
Void Int0Init ()//A/D conversion external interrupt
{
IT0=1;
EX0=1;
EA=1;
}
Void Int0 () interrupt 0
{
If (INTR==0)
{
P1=0 XFF;//read digital signal when the P1 mouth first buy 1
//ADCRD=1;
//_nop_ ();
ADCRD=0;//A/D reading can make
_nop_();
Data=https://bbs.csdn.net/topics/P1;
ADCRD=1;
_nop_();
}
ADC_init ();
}
Void main ()
{
//Serial_init ();//serial port register initialization setting
Delay_Ms (1000);//delay, fully initialized
Xuantong=0;//strobe ADC0804 chip
Timer0Init ();
ADC_init ();
Int0Init ();
While (1)
{

If (Data<50 & amp; & Data>=0)//duty ratio 20%
{
If (flag1==0)
{
Flag1=1;
Flag2=0;
Flag3=0;
X0b Play_music (0);
}
PWM=20;
}
Else if (Data>=50 & amp; & Data<80)//duty ratio 50%
{
//if (flag2==0)
//{
//flag2=1;
//flag1=0;
//flag3=0;
//Play_music x0c (0);
//}
PWM=50;

}
The else//duty ratio 90%
{
//if (flag3==0)
//{
//flag3=1;
//flag2=0;
//flag1=0;
//Play_music x0d (0);
//}
PWM=90;
}
//if (time==100)//
//time=0;
//else if (time<=PWM)
//{
//the led=1;
//}
//else
//the led=0;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- functions: chip electrically specified respectively the first and second song, basic application for users to test
- date: 2013-05-06
- running environment: on STC crystals: 11.0592 M baud rate: 9600
- note: on the 51 development in science and technology's board debugging OK - STC89C516RD +
1, the test program must be module or chip package equipment online, such as U disk, TF card, FLASH
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "REG52. H"
# include "music. H"
9600////# define COMM_BAUD_RATE serial port baud rate
11059200////# define OSC_FREQ run crystals: 11.05926 MHZ
//typedef unsigned char INT8U;
//typedef unsigned int INT16U;
//typedef unsigned long INT32U;
The static INT8U Send_buf [10]={0};
Void Delay_Ms (INT32U z)
{
INT32U x=0, y=0;
For (x=110; x> 0; X -)
For (y=z; Y> 0; Y -);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Initialization - functional description: serial port 1
- note: set to 9600 baud rate
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//void Serial_init (void)
//{
////IP=0 x10;
//TMOD |=0 x20;//set the T1 to baud rate generator
//SCON=0 x50;//0101000 0 8 bits of data, and white parity
//PCON=0 x00;//PCON=0;
//TH1=256 - (OSC_FREQ COMM_BAUD_RATE/32/12);//set to 9600 baud rate
//TL1=256 - (OSC_FREQ COMM_BAUD_RATE/32/12);
//TR1=1;//open the timer 1
//REN=1;//serial port 1 received enabled
//ES=1;//serial port interrupts enabled
1//}
Void Uart_PutByte INT8U (ch)
{
SBUF=ch;
//while (! TI);
//TI=0;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- functional description: a serial port to send commands [including control and query]
- parameters description: CMD: it means the control instruction, please refer to instruction table, also include query related instructions
Feedback: if you need reply [0: no need to reply 1: need to reply]
Data: the parameters of the transmission
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void SendCmd (INT8U len)
{
INT8U I=0;
X7e Uart_PutByte (0);//start
for(i=0; i{
Uart_PutByte (Send_buf [I]);
}
Uart_PutByte xef (0);//end
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull