?? ad9850.c
字號:
//ad9850源程序
#include <reg51.h>
#include <stdio.h>
#include <absacc.h>
#include <intrins.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define Zero 0x30
#define One 0x31
#define Two 0x32
#define Three 0x33
#define Four 0x34
#define Five 0x35
#define Six 0x36
#define Seven 0x37
#define Eight 0x38
#define Nine 0x39
//鍵盤毽值
#define Key_0 24
#define Key_1 25
#define Key_2 17
#define Key_3 9
#define Key_4 26
#define Key_5 18
#define Key_6 10
#define Key_7 27
#define Key_8 19
#define Key_9 11
#define Freq_Step_Up 0
#define Freq_Step_Down 1
#define Set_Freq 2
#define Key_Sure 3
#define Para 35.7913941333 //
// 光標(biāo)參數(shù)
#define NoDisp 0
#define NoCur 1
#define CurNoFlash 2
#define CurFlash 3
//鍵盤控制字
#define HD7279_READ 0x15 //讀
#define HD7279_RESET 0xa4 //復(fù)位
/*--------------------------------------------
調(diào)用方式:自行I/O 口定義
函數(shù)說明:各接口定義
--------------------------------------------*/
sbit HD7279_CS = P1^5; // HD7279_CS -- P3.5
sbit HD7279_CLK = P1^4; // HD7279_CLK -- P3.4
sbit HD7279_DATA = P1^3; // HD7279_DATA-- P3.7
sbit HD7279_KEY = P3^2; // HD7279_KEY -- P3.2
//ad9851的控制線
sbit Data_Bus = P1^0;
sbit W_CLK = P1^1;
sbit FQ_UD = P1^2;
//lcd的控制線
sbit RS = P2^7;
sbit RW = P2^6;
sbit E = P2^5;
uchar Xpos; //列方向地址指針
uchar Ypos; //行方向地址指針
//ad9851的變量
long Fout = 100;
float Frequancy_Com = 0;
uchar Frequancy_Command[5] = {0x44,0x44,0x44,0x04,0x01}; //2Mhz的配置字
//鍵盤的變量
uchar Key;
bit Key_Interupt_Flag = 0;
bit Error_Flag = 0;
bit Set_Key = 0;
uchar Input_Data_Count = 0;
//液晶的變量
uchar Freq_Disp_Buf[8] = {0x4f,0xa5,0x4f,0x4f,0x4f,0x4f,0x4f,0x4f}; //初始化顯示的字符
uchar code blank_disp[]={" "};//將錯誤信息清除
//函數(shù)聲明
void WaitreadBF();
void LcdWcn(uchar);
void LcdWc(uchar);
void WriteChar(uchar);
void LcdPos();
void LcdWd(uchar);
void LcdWdn(uchar);
void HD7279_LongDelay();
void HD7279_ShortDelay();
void Delay1ms(uchar);
void HD7279_SendByte(uchar);
void Write7279(uchar,uchar);
uchar Read7279(uchar);
uchar HD7279_ReceiveByte();
uchar HD7279_GetKey();
void LCD_Display(uchar Xpos1,uchar Ypos1,uchar str[]);
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Delay(int count)
{
uchar i;
for(;count > 0;count--)
for(i=50;i>0;i--)
{;}
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Ad9850_SendData(uchar Data)
{
uchar j,Dat;
Dat = Data;
Delay(10);
for(j=0;j<8;j++)
{
if (Dat&1)
{
Data_Bus = 1;
}
else
{
Data_Bus = 0;
}
W_CLK = 0;
W_CLK = 1;
Dat = Dat >> 1;
Data_Bus = 0;
W_CLK = 0;
FQ_UD = 0;
}
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Reset_Ad9851()
{
Data_Bus = 0;
W_CLK = 0;
FQ_UD = 0;
W_CLK = 1;
W_CLK = 0;
Delay(50);
FQ_UD = 1;
Delay(10);
FQ_UD = 0;
Ad9850_SendData(0x00);
FQ_UD = 1;
Delay(10);
FQ_UD = 0;
Delay(10);
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Write_Data_Ad9850(uchar Number,uchar *Write_Data)
{
Reset_Ad9851();
for(;Number > 0;Number--)
{
Ad9850_SendData(*Write_Data);
Write_Data++;
}
FQ_UD = 1;
Delay(50);
FQ_UD = 0;
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能#海海? 實現(xiàn)100hz的步進
傳遞參數(shù):
----------------------------------------------------*/
void Freq_Step_Increase()
{
Fout = Fout + 100;
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Freq_Step_Decrease()
{
uchar Message_Box[]={"Error!Frequancy below 0hz!"};
Fout = Fout - 100;
if(Fout < 10)
{
LCD_Display(0,0,Message_Box);
Error_Flag = 1;
Fout = 1000000;
}
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Frequancy_Control_Convert(long Frequancy)
{
long Freq_Conv;
Frequancy_Com = Frequancy * Para;
Freq_Conv = (long)Frequancy_Com;
Frequancy_Command[0] = (uchar)(Freq_Conv&0x000000ff);
Freq_Conv = Freq_Conv>>8;
Frequancy_Command[1] = (uchar)(Freq_Conv&0x000000ff);
Freq_Conv = Freq_Conv>>8;
Frequancy_Command[2] = (uchar)(Freq_Conv&0x000000ff);
Freq_Conv = Freq_Conv>>8;
Frequancy_Command[3] = (uchar)(Freq_Conv&0x000000ff);
Frequancy_Command[4] = 0x81;
}
/*--------------------------------------------
函數(shù)名稱?函數(shù)說明:例函數(shù)
--------------------------------------------*/
/*
void Key_Scan()
{
if(Function_Up == 0)
{
Fout = Fout << 4;
Fout = Fout |
}
}
*/
/********************************************************************
延時程序
由Delay參數(shù)確定延遲時間
********************************************************************/
void mDelay(unsigned int Delay)
{
unsigned int i;
for(;Delay>0;Delay--)
{
for(i=0;i<124;i++)
{;}
}
}
/********************************************************************
送控制字子程序
********************************************************************/
void LcdWcn(uchar c)
{
RS = 0;
RW = 0;
P0=c;
E = 1;
_nop_();
E = 0;
}
/********************************************************************
檢測忙信號的送控制字子程序
********************************************************************/
void LcdWc(uchar c)
{
WaitreadBF();
LcdWcn(c);
}
/********************************************************************
光標(biāo)設(shè)置命令
Cur 為設(shè)定光標(biāo)參數(shù)
********************************************************************/
void SetCur(uchar Cur)
{
switch(Cur)
{ case 0x0:
{
LcdWc(0x08); //關(guān)顯示
break;
}
case 0x1:
{
LcdWc(0x0c); //開顯示但無光標(biāo)
break;
}
case 0x2:
{
LcdWc(0x0e); //開顯示有光標(biāo)但不閃爍
break;
}
case 0x3:
{
LcdWc(0x0f); //開顯示有光標(biāo)且閃爍
break;
}
default: break;
}
}
/********************************************************************
清屏命令
********************************************************************/
void ClrLcd()
{
LcdWc(0x01);
}
/********************************************************************
在指定的行與列顯示
********************************************************************/
void WriteChar(uchar c)
{
LcdPos();
LcdWd(c);
}
/********************************************************************
正常讀寫操作之前檢測LCD控制器
********************************************************************/
void WaitreadBF()
{
uchar tmp;
P0=0xff;
RS = 0;
RW = 1;
E = 1;
_nop_();
for(;;)
{
tmp = P0;
tmp&=0x80;
if(tmp==0)
break;
}
E = 0;
}
/********************************************************************
寫字符子程序
********************************************************************/
void LcdWdn(uchar c)
{
RS = 1;
RW = 0;
P0=c; //寫入待寫字符
E = 1;
_nop_();
E = 0;
}
/********************************************************************
帶忙檢測的寫字符子程序
********************************************************************/
void LcdWd(uchar c)
{
WaitreadBF();
LcdWdn(c);
}
/********************************************************************
********************************************************************/
void LcdPos()
{
uchar tmp;
Xpos&=0x3f; //402型液晶的范圍是0~39
Ypos&=0x01; //Y的范圍是0~1
tmp=Xpos;
if(Ypos==1)
{
tmp+=0x40;
}
tmp|=0x80;
LcdWc(tmp);
}
/********************************************************************
LCD的復(fù)位程序
********************************************************************/
void RstLcd()
{
mDelay(15); //延時15ms
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);
mDelay(5);
LcdWcn(0x38);
LcdWc(0x38);
LcdWc(0x08);
LcdWc(0x01);
LcdWc(0x06);
LcdWc(0x0c);
}
/********************************************************************
********************************************************************/
void WriteString(char s[])
{
uchar pS = 0;
for(;;)
{
WriteChar(s[pS]);
pS++;
if(s[pS]==0)
break;
if(++Xpos>=39) //每行最多顯示40個字符
break;
}
}
/********************************************************************
顯示字符
參數(shù) Xpos1 Ypos1 str[]
********************************************************************/
void LCD_Display(uchar Xpos1,uchar Ypos1,uchar str[])
{
Xpos = Xpos1;
Ypos = Ypos1;
WriteString(str);
}
/*--------------------------------------------------
函數(shù)名稱:
函數(shù)功能:
傳遞參數(shù):
----------------------------------------------------*/
void Lcd_Any_Disp(uchar xsite,uchar ysite,uchar Data)
{
Xpos = xsite;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -