//******************************//
//**********主控部分程序********//
//******************************//
#include<reg52.h>
#include<intrins.h>
#include<LCD12864.h>
//******参数设置引脚设置******//
sbit guangbiao_jia =P2^3;
sbit guangbiao_jian=P2^4;
sbit shuzi_jia =P2^5;
sbit shuzi_jian =P2^6;
sbit queren =P2^7;
uchar carry[]={'0','0','0','0','0','1','\0'}; //频率步进数组
uchar table_A[]={'0','0','0','0','1','0','0','0','\0'}; //A路频率数组
uchar table_B[]={'0','0','0','0','1','0','0','0','\0'}; //B路频率数组
uchar table_AM[]={'1','.','0','\0'}; //A路幅度数组
uchar table_BM[]={'1','.','0','\0'}; //B路幅度数组
uchar table_P[]={'0','0','0','\0'}; //相位差数组
uchar table_F[]={'1',':','1','\0'}; //频率比数组
uchar clear[]={' ','\0'}; //清除数据
unsigned long int count_carry=1; //频率步进初始值
unsigned long int count_fre_A=1000;//A路频率初始值
unsigned long int count_fre_B=1000;//B路频率初始值
unsigned long int Fre_A_Binary=0;//通道A二进制频率数
unsigned long int Fre_B_Binary=0;//通道B二进制频率数
unsigned int Phase_Binary=0; //二进制相位差
uchar count_AM=10; //A路幅度初始值1.0V
uchar count_BM=10; //B路幅度初始值1.0V
uchar count_Phase; //相位差之值
uchar fenzi=1,fenmu=1; //A,B路频率初始比值1:1
float amplitude_A,amplitude_B; //A,B最终幅度值
uchar guangbiao; //记录光标位置
bit flag; //记录闪烁条件 0----不闪 1----闪
bit mos_set; //跳出参数模式设置 0---跳出 1---进入调节
bit counter; //记录A、B频率单独变化还是同时(当调节频率比时)变化
// 0----单独变化 1-----同时变化
bit send; //数据发送标志位 0----不发送 1----发送
//=========================================//
void delay_ms(uint z)//1ms延时
{
uint x,y;
for(x=z;x>0;x--)
for(y=120;y>0;y--);
}
//**********基本参数符号显示***********//
void base_show()
{
gotoxy(1,0);
print("HZ");
mdelay(10);
gotoxy(1,2);
print("℃");
mdelay(10);
gotoxy(1,4);
print("V");
mdelay(10);
gotoxy(2,0);
print("A:");
mdelay(10);
gotoxy(3,0);
print("B:");
mdelay(10);
gotoxy(4,0);
print("P:");
mdelay(10);
gotoxy(4,4);
print("AB:");
mdelay(10);
}
//********参数显示函数**********//
void data_show()
{
gotoxy(1,5);
print(carry);
mdelay(10);
gotoxy(2,1);
print(table_A);
mdelay(10);
gotoxy(2,6);
print(table_AM);
mdelay(10);
gotoxy(3,1);
print(table_B);
mdelay(10);
gotoxy(3,6);
print(table_BM);
mdelay(10);
gotoxy(4,1);
print(table_P);
mdelay(10);
gotoxy(4,6);
print(table_F);
mdelay(10);
}
//==========================================//
//******数据发送函数**********//
void send_data()
{
uchar MCU_data;
/***********十进制量转成赋值二进制量****************/
Fre_A_Binary=count_fre_A*171.798692;//每HZ赋值 171.79869184
Fre_B_Binary=count_fre_B*171.798692;
if(count_Phase%45==0)//能被45整除
{
Phase_Binary=512*(count_Phase/45);//512的n倍
}
else//非特殊角
{
Phase_Binary=(unsigned int)(count_Phase*11.3777);//每°赋值 11.3777
}
/***********十进制量转成赋值二进制量****************/
//测试通过!!
/***********发送数据固定流程***************/
MCU_data=0xff;//8'b1111_1111;//单片机默认高电平
P1=MCU_data;
delay_ms(10);
/***********-----A路频率------********/// 000 100 001 010 000 011 001 000
// MCU_data=0xe8 ;//1 5'b1110 1-000
MCU_data=0xe8|(Fre_A_Binary%8);//地址|数据 数据以三位三位的出
Fre_A_Binary=Fre_A_Binary/8;//舍弃处理完的低三位
P1=MCU_data;
delay_ms(1);
// MCU_data=0xe0 ;//2 5'b1110 0-000
MCU_data=0xe0|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0xa2 ;//3 5'b1010 0-010
MCU_data=0xa0|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0xac ;//4 5'b1010 1-100
MCU_data=0xa8|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0xbb ;//5 5'b1011 1-011
MCU_data=0xb8|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0xb0 ;//6 5'b1011 0-000
MCU_data=0xb0|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x94 ;//7 5'b1001 0-100
MCU_data=0x90|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x99 ;//8 5'b1001 1-001
MCU_data=0x98|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x88 ;//9 5'b1000 1-000
MCU_data=0x88|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x80 ;//10 5'b1000 0-000
MCU_data=0x80|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x00 ;//11 5'b0000 0-000
MCU_data=0x00|(Fre_A_Binary%8);
Fre_A_Binary=Fre_A_Binary/8;
P1=MCU_data;
delay_ms(1);
/***********-----B路频率------********/
// MCU_data=0x08 ;//1 5'b0000 1- MCU_data=0x08|(Fre_B_Binary%8);
MCU_data=0x08|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x18 ;//2 5'b0001 1-000
MCU_data=0x18|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x12 ;//3 5'b0001 0-010
MCU_data=0x10|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x34 ;//4 5'b0011 0-100
MCU_data=0x30|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x3b ;//5 5'b0011 1-011
MCU_data=0x38|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x28 ;//6 5'b0010 1-000
MCU_data=0x28|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x24 ;//7 5'b0010 0-100
MCU_data=0x20|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x61 ;//8 5'b0110 0-001
MCU_data=0x60|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x68 ;//9 5'b0110 1-000
MCU_data=0x68|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x78 ;//10 5'b0111 1-000
MCU_data=0x78|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x70 ;//11 5'b0111 0-000
MCU_data=0x70|(Fre_B_Binary%8);
Fre_B_Binary=Fre_B_Binary/8;
P1=MCU_data;
delay_ms(1);
/**************------相位差数据发送---------******/// 0 010 100 010
// MCU_data=0x50 ;//1 5'b0101 0-
MCU_data=0x50|(Phase_Binary%8);
Phase_Binary=Phase_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x58 ;//2 5'b0101 1-000
MCU_data=0x58|(Phase_Binary%8);
Phase_Binary=Phase_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x48 ;//3 5'b0100 1-000
MCU_data=0x48|(Phase_Binary%8);
Phase_Binary=Phase_Binary/8;
P1=MCU_data;
delay_ms(1);
// MCU_data=0x42 ;//4 5'b0100 0-010
MCU_data=0x40|(Phase_Binary%8);
Phase_Binary=Phase_Binary/8;
P1=MCU_data;
delay_ms(1);
//-----------------------------------------------//
MCU_data=0xf0 ;// 5'b1111 0-000 //输出更新置位
P1=MCU_data;
delay_ms(1);
MCU_data=0xff;//8'b1111_1111;
P1=MCU_data;
delay_ms(10);
}
//================================================//
//*********幅度输出*************//
void fudu()
{
P3=5*amplitude_A;
}
//********光标键盘扫描函数*********//
void guangbiao_key_scan()
{
if(guangbiao_jia==0)
{
mdelay(120);
if(guangbiao_jia==0)
{
guangbiao++;
data_show();//防掉显
评论1
最新资源