应用AD9850函数说明
0赞
发表于 4/24/2012 9:28:27 AM
阅读(39127)
/**********************************************************
延时子函数
**********************************************************/
void delayms(unsigned int ms)
{
unsigned char t;
while (ms--)
{
for (t = 0; t < 114; t++)
;
}
}
/*************************************************************/
/* */
/*检查LCD忙状态 */
/*lcd_busy为时,忙,等待。lcd-busy为时,闲,可写指令与数据 */
/* */
/*************************************************************/
bit lcd_busy()
{
bit result;
LCD_RS = 0;
LCD_RW = 1;
LCD_EN = 1;
delayNOP();
result = (bit)(P3&0x80);
LCD_EN = 0;
return(result);
}
/**************************************************************/
/* */
/*写指令数据到LCD */
/*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 */
/* */
/**************************************************************/
void lcd_wcmd(uchar cmd)
{
while(lcd_busy());
LCD_RS = 0;
LCD_RW = 0;
LCD_EN = 0;
_nop_();
_nop_();
P3 = cmd;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*******************************************************************/
/* */
/*写显示数据到LCD */
/*RS=H,RW=L,E=高脉冲,D0-D7=数据。 */
/* */
/*******************************************************************/
void lcd_wdat(uchar dat)
{
while(lcd_busy());
LCD_RS = 1;
LCD_RW = 0;
LCD_EN = 0;
P3 = dat;
delayNOP();
LCD_EN = 1;
delayNOP();
LCD_EN = 0;
}
/*************************************************************/
/* */
/* LCD初始化设定 */
/* */
/*************************************************************/
void lcd_init()
{
delayms(15);
lcd_wcmd(0x38); //16*2显示,*7点阵,位数据
delayms(5);
lcd_wcmd(0x38);
delayms(5);
lcd_wcmd(0x38);
delayms(5);
lcd_wcmd(0x0c); //显示开,关光标
delayms(5);
lcd_wcmd(0x06); //移动光标
delayms(5);
lcd_wcmd(0x01); //清除LCD的显示内容
delayms(5);
}
/**********************************************************
写字符串函数
**********************************************************/
void write_str(uchar addr, uchar *p)
{
uchar i =0;
lcd_wcmd(addr);
while (p[i] != '\0')
{
lcd_wdat(p[i]);
i++;
}
}
/*************************************************************/
/* */
/* 设定显示位置 */
/* */
/*************************************************************/
void lcd_pos(uchar row, uchar col)
{
uchar place;
if (row == 1)
{
place = 0x80 + col - 1;
lcd_wcmd(place);
}
if (row == 2)
{
place = 0xc0 + col - 1;
lcd_wcmd(place);
}
}
/************************************************************/
/*ad9850复位 */
/************************************************************/
void AD9851_RST(void)
{
RST = 1;
_nop_();
RST = 0;
W_CLK = 0;
FQ_UD = 0;
}
/***********************************************************/
/* */
/* AD9850参数设置程序 */
/* */
/***********************************************************/
void AD9851_SET(float fre)
{
union
{
unsigned long int det1;
struct{uchar dhh;uchar dhl;uchar dlh;uchar dll; }det2;
}dat;
dat.det1=fre*35.79139;
//dat.det1=1000000*35.79139;
P0 = 0x01;
W_CLK=1;
W_CLK=0;
P0 =dat.det2.dhh;
W_CLK=1;
W_CLK=0;
P0 =dat.det2.dhl;
W_CLK=1;
W_CLK=0;
P0 =dat.det2.dlh;
W_CLK=1;
W_CLK=0;
P0 =dat.det2.dll;
W_CLK=1;
W_CLK=0;
FQ_UD=1;
FQ_UD=0;
}
