?? write_9851.c
字號:
#include <math.h>
#include <stdio.h>
#include <reg52.h>
#define uc unsigned char
#define ui unsigned int
//端口定義
sbit cs=P1^0;
sbit clk=P1^1;
sbit dat=P1^2;
sbit e=P1^3;
sbit rs=P1^4;
sbit ab=P1^5;
sbit clock=P1^6;
sbit xa=P1^7;
sbit xb=P3^0;
sbit xc=P3^1;
sbit xd=P3^7;
sbit key=P3^2; //7279按鍵有效輸出端
sbit w_clk=P3^3;
sbit eq_ud=P3^4;
sbit rst=P3^5;
//變量及數組定義
unsigned long fout; //輸出頻率
unsigned long fou; //頻率暫時存儲
float ff; //頻率控制字
//.float pi2=8.0*atan(1.0);
bit idata flag0; //小數點標志
bit idata flag1; //設置頻率標志
bit idata flag2; //有無單位按下標志
bit idata flag3; //有無數字鍵按下標志
bit idata flag4; //頻偏5KHz
bit idata flag5; //頻偏10KHz
uc idata i; //全局變量
uc idata xsd; //小數點位置
uc idata zc; //輸入頻率的位數
uc idata sm; //掃頻次數
uc idata kzhi[5]; //頻率控制字
uc idata shuju[8]; //待顯示頻率數據
uc idata fs[10]; //頻率設置單元
uc code keydata[24]={7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8,23,22,21,20,19,18,17,16};
uc code aaa[11]={0x24,0x24,0x24,0x24,0x25,0x25,0x25,0x25,0x25,0x26,0x26};
uc code bbb[11]={0x68,0x97,0xc5,0xf4,0x23,0x51,0x80,0xae,0xdd,0x0c,0xca};
uc code ccc[11]={0xac,0x47,0xe1,0x7c,0x16,0xb1,0x4b,0xe6,0x80,0x1b,0xb5};
//按鍵編碼
//函數定義
void send_7279(uc);
void setup1(void); //液晶初始化
void wr_com(uc); //液晶寫命令
void wr_data(uc,uc,uc);//對液晶寫數據,參數分別為地址,寫的個數,及數據
void wr_da(uc); //液晶寫字節
//********* 延時2uS為基值 ****************
void delay(ui dl)
{
while(dl--);
}
//***********************
void setup0(void)
{
dat=0; //7279初始化
clk=0;
key=1;
cs=1;
delay(5);
send_7279(0xa4); //復位清除
cs=1;
}
//********* 發數據或指令到7279 **********
void send_7279(uc dout)
{
uc i;
cs=0;
delay(13);
for(i=0;i<8;i++)
{dat=(dout&0x80)?1:0;
clk=1;
delay(3);
clk=0;
delay(3);
dout<<=1;
}
dat=0;
}
//**********************
void setup1(void)
{
wr_com(0x01); //清除顯示
wr_com(0x01);
//wr_com(0x0c);
//wr_com(0x0e); //顯示光標,游標(一定要開顯示)
wr_com(0x0d);
}
//***************
//***************
void wr_com(uc command)
{
uc j;
delay(250);
rs=0;
for(j=0;j<8;j++)
{
ab=(command&0x80)?1:0;
clock=1;
clock=0;
command<<=1;
}
e=1;
e=0;
}
//*********************
void wr_data(uc pos1,uc end,uc *ap)
{
uc i;
wr_com(pos1);
for(i=0;i<end;i++,ap++) wr_da(*ap);
}
//*********************
void wr_da(uc dat)
{
uc j;
delay(250);
rs=1;
for(j=0;j<8;j++)
{
ab=(dat&0x80)?1:0;
clock=1;
clock=0;
dat<<=1;
}
e=1;
e=0;
}
//**********************************
void fre_sf(void)
{
uc j;
ff=23.860929*fout;
kzhi[1]=ff/0x1000000;
kzhi[2]=ff/0x10000;
kzhi[3]=ff/0x100;
kzhi[4]=ff/1;
xa=1;
xb=1;
xc=1;
xd=1;
w_clk=0;
eq_ud=0;
rst=0;
for(j=0;j<5;j++)
{
P2=kzhi[j];
w_clk=1;
w_clk=0;
}
eq_ud=1;
shuju[0]=fout/10000000;
shuju[1]=fout%10000000/1000000;
shuju[2]=fout%1000000/100000;
shuju[3]=fout%100000/10000;
shuju[4]=fout%10000/1000;
shuju[5]=fout%1000/100;
shuju[6]=fout%100/10;
shuju[7]=fout%10;
//if(fout<1000000) {
// xa=0;
// }
// else if(fout<3000000) {
// xb=0;
// }
// else if(fout<6000000) {
// xc=0;
// }
//else {
// xd=0;
// }
if(ff<8000000) xa=0;
else xb=0;
if(fout<1000) {
if(fout<10){ shuju[0]=shuju[7];
shuju[1]=0x2e;
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
//shuju[6]=0;
shuju[7]=0;
}
else if(fout<100)
{
shuju[0]=shuju[6];
shuju[1]=shuju[7];
shuju[2]=0x2e;
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
shuju[6]=0;
shuju[7]=0;
}
else if(fout<1000)
{
shuju[0]=shuju[5];
shuju[1]=shuju[6];
shuju[2]=shuju[7];
shuju[3]=0x2e;
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
shuju[5]=0;
shuju[6]=0;
shuju[7]=0;
}
}
else if(fout<1000000)
{
if(fout<10000)
{
shuju[0]=shuju[4];
shuju[1]=0x2e;
shuju[2]=shuju[5];
shuju[3]=shuju[6];
shuju[4]=shuju[7];
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
shuju[5]=0;
shuju[6]=0;
}
else if(fout<100000)
{
shuju[0]=shuju[3];
shuju[1]=shuju[4];
shuju[2]=0x2e;
shuju[3]=shuju[5];
shuju[4]=shuju[6];
shuju[5]=shuju[7];
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
shuju[6]=0;
}
else if(fout<1000000)
{
shuju[0]=shuju[2];
shuju[1]=shuju[3];
shuju[2]=shuju[4];
shuju[3]=0x2e;
shuju[4]=shuju[5];
shuju[5]=shuju[6];
shuju[6]=shuju[7];
//shuju[2]=0;
//shuju[3]=0;
//shuju[4]=0;
//shuju[5]=0;
}
shuju[7]='K'-48;
}
else if(fout>=1000000)
{
if(fout<10000000) {
shuju[0]=shuju[1];
shuju[1]=0x2e;
shuju[2]=shuju[2];
shuju[3]=shuju[3];
shuju[4]=shuju[4];
shuju[5]=shuju[5];
shuju[6]=shuju[6];
}
else {
//shuju[0]=shuju[1];
//shuju[1]=shuju[2];
shuju[6]=shuju[5];
shuju[5]=shuju[4];
shuju[4]=shuju[3];
shuju[3]=shuju[2];
shuju[2]=0x2e;
}
shuju[7]='M'-48;
}
//wr_com(0x01);
//wr_data(0x80,16," DDS輸出頻率 ");//第一行顯示
wr_com(0x90);
wr_da(' ');
wr_da(' ');
wr_da(' ');
for(j=0;j<8;j++) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -