天津工业大学本科毕业论文 附录
TCON=0x40; PCON=0x00; TH1=0x0bc; TL1=0x0bc; TR1=1;
TI=0;
P2=0x03;//选择IN3端口
while(1)
{
ad0809(); while(EOC==0); OE=1; _nop_(); dout=P0; P1=dout; fa_song(); OE=0; } }
接收程序: #include
/*3个数码管所需的3个位用来做38译码*/ sbit SEL0=P2^0; sbit SEL1=P2^1; sbit SEL2=P2^2;
/*4个挡位****************************/ sbit KEY1=P2^4;//1K~10K sbit KEY2=P2^5;//10K~100K sbit KEY3=P2^6;//100K~1000K sbit KEY4=P2^7;//1M~10M sbit P32=P3^2;//4个挡位公用一个键 sbit P33=P3^3;//加100HZ unsigned long count1; unsigned long count2; unsigned long count3; unsigned long count4; unsigned long count5;
36
天津工业大学本科毕业论文 附录
unsigned long sum;
/*AD8951定义的变量***********/ unsigned char con_word[5];
unsigned long K;//K=count*2386;k=fo*23.86,因为fo=count*100所以k=count*2386
sbit FQ_UD=P3^6; sbit W_CLK=P3^7; sbit we=P3^4;
/*通信用的端口定义与FM的产生***********/ unsigned char asd;//存储1KHZ调制信号的幅度 sbit KEY_FM=P3^5;
unsigned char code tab[]={0x0c0,0x0f9,0x0a4,0x0b0,0x99,0x92,0x82,0x0f8,0x80,0x90};
/*用来控制1~9的加数来对4个挡位执行加法..p32的键,中断0***********************************/
void int0(void)interrupt 0 using 0//缓慢加100
{
if(KEY1==0)//1k~10K {
if(count1==100) count1=0; else {
count1=count1+10; } }
if(KEY2==0)//10k~100K {
if(count2==1000) count2=0; else {
count2=count2+100; } }
if(KEY3==0)//100k~1000K {
if(count3==10000)
37
天津工业大学本科毕业论文 附录
count3=0; else {
count3=count3+1000; } }
if(KEY4==0)//1M~10M {
if(count4==100000) count4=0; else {
count4=count4+10000; //
K=count*14316;k=fo*143.16,因为fo=count*100所以k=count*14316
} } }
/*步进100HZ用中断*************************************/ void int1(void)interrupt 2 using 2//P3.3 {
if(count5==100000) count5=0; else {
count5=count5+1;//步进100HZ }
}
/* 数码管扫描 ************************************** */ void shu_ma_guan(void) {unsigned char i;
sum=(count1+count2+count3+count4+count5)*100; P0=tab[sum]; //个位第一个数码管以下依次类推 SEL0=0;SEL1=0;SEL2=0; for(i=0;i<255;i++); P0=tab[sum0/10];//十位
38
天津工业大学本科毕业论文 附录
SEL0=1;SEL1=0;SEL2=0; for(i=0;i<255;i++); P0=tab[sum00/100];//百位 SEL0=0;SEL1=1;SEL2=0; for(i=0;i<255;i++); P0=tab[sum000/1000];//千位 SEL0=1;SEL1=1;SEL2=0; for(i=0;i<255;i++);
P0=tab[sum0000/10000];//万位 SEL0=0;SEL1=0;SEL2=1; for(i=0;i<255;i++);
P0=tab[sum00000/100000];//十万位 SEL0=1;SEL1=0;SEL2=1; for(i=0;i<255;i++);
P0=tab[sum000000/1000000];//百万位 SEL0=0;SEL1=1;SEL2=1; for(i=0;i<255;i++); P0=tab[sum/10000000];//千万位 SEL0=1;SEL1=1;SEL2=1; for(i=0;i<255;i++); }
/*计算*****************************************/ void jisuan(void) {
con_word[0]=0x01;
con_word[1]=K/0x1000000;//主高位先发送,然后接着往下发
con_word[2]=K%0x1000000/0x10000; con_word[3]=K%0x10000/0x100; con_word[4]=K%0x100;//sum%0x100 }
/*发送数据*****************************/ void write_ad9850(void) {
unsigned char i; unsigned char j; unsigned char m; FQ_UD=0;
39
天津工业大学本科毕业论文 W_CLK=0;
for(m=0;m<1;m++);//yan shi for(i=0;i<5;i++)
{ P1=con_word[i]; W_CLK=0;
for(j=0;j<1;j++); //yan shi W_CLK=1; for(j=0;j<1;j++);//yan shi }
FQ_UD=1;
for(m=0;m<1;m++);//yan shi FQ_UD=0; }
/*接受第一快单片机发来的数据*************/ void jie_shou(void) {
while(RI==0);
asd=SBUF;//asd是二进制值,电压V= RI=0; }
/*定时查键*********************************** void timer0(void)interrupt 1 using 1 {
TR0=0;
shu_ma_guan(); TH0=-1000/256; TL0=-1000%6; TR0=1; }*/
void main(void) {
SCON=0x50; TMOD=0x20; TCON=0x40; PCON=0x00; TH1=0x0bc; TL1=0x0bc;
40
附录
asd/51;