#include<reg52.h>
#define Ch1Mode 0x00 // ͨµÀ1¹¤×÷ģʽ
#define Ch1Freq 0x01 //ͨµÀ1Êä³öƵÂÊÉ趨
#define Ch1Step 0x02 //ͨµÀ1²½½øÔöÁ¿
#define Ch2Mode 0x04 //ͨµÀ2¹¤×÷ģʽ
#define Ch2Freq 0x05 //ͨµÀ2Êä³öƵÂÊÉ趨
#define Ch2Step 0x06 //ͨµÀ2²½½øÔöÁ¿
#define Ch3Mode 0x08 //ͨµÀ3¹¤×÷ģʽ
#define Ch3Freq 0x09 //ͨµÀ3Êä³öƵÂÊÉ趨
#define Ch3Step 0x0A //ͨµÀ3²½½øÔöÁ¿
#define SynMode 0x0c //ͬ²½Ä£Ê½
#define uchar unsigned char
#define uint unsigned int
sbit ji=PSW^0;
/*********msÑÓʱ³ÌÐò***********/
void delayms(uint x)
{
uchar i,j;
for(i=x;i>0;i--)
for(j=0;j<110;j++);
}
/*********³õʼ»¯***************/
void Seril_init(void)
{
delayms(1); //ÑÓʱ´óÓÚ50us
TMOD=0x20;
TH1=0xfd; //²¨ÌØÂÊ9600bps
TL1=0xfd;
TR1=1;
SCON=0xD0; //ÔÊÐí½ÓÊÕ
TI=1;
EA=0;
}
/***********дÊý¾Ýº¯Êý*************/
void Write_data(uchar addr,uchar date)
{
uchar Send_data;
Send_data=0x50|addr;
TB8=ji^0x01;
SBUF=Send_data;
while(TI==0);TI=0;
delayms(5);
Send_data=date;
TB8=ji^0x01;
SBUF=Send_data;
while(TI==0);TI=0;
delayms(5);
}
/*********¶ÁÊý¾Ýº¯Êý***********/
uchar Read_data(uchar addr)
{
uchar Receive_data;
uchar Send_data;
Send_data=0xA0|addr;
SBUF=Send_data;
while(TI==0);TI=0;
while(RI==0);RI=0;
Receive_data=SBUF;
return Receive_data;
}
void main()
{
Seril_init();
while(1)
{
Write_data(Ch1Mode,0x80); //²½½øµç»úÕýÏò£¬×ÔÓÉÅÜ£¬È«²½
Write_data(Ch1Freq,0xf0); //Êä³öƵÂÊf=4k/(Ch1Freq+1)
}
}