#include "set.c"
main()
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD
P1DIR|=0XFF
P2DIR|=(BIT1+BIT2+BIT3+BIT4)
CSA_H
CSB_H
WR_H
lcd_init()
/源租*for(i=0i<=500i++)
{
__delay_cycles(300000)
}*/
B_Dload(0)
Display_string(0,0,"welcome!")
Display_string(0,1," set_gain:0")
while(1)
{
key_set()
switch(num)
{
case 0:set_am()break
default:break
}
}
}
#define CSA_H (P4DIR|=BIT6,P4OUT|=BIT6)
#define CSA_L (P4DIR|=BIT6,P4OUT&=~BIT6)
#define CSB_H (P4DIR|=BIT4,P4OUT|=BIT4)
#define CSB_L (P4DIR|=BIT4,P4OUT&=~BIT4)
#define WR_H (P4DIR|=BIT5,P4OUT|=BIT5)
#define WR_L (P4DIR|=BIT5,P4OUT&=~BIT5)
#define DATA_L_OUT P1OUT //主函数里要将对应P口设成输出状态
#define DATA_H_OUT P2OUT
char out1,out2
void data(int xx)
{
out1=xx
DATA_L_OUT=out1
out2=xx>>7//因为p2.0坏了所以移动了7位,没坏的要移动8位
DATA_H_OUT=out2
}
void A_Dload(int yy)
{
data(yy)
__delay_cycles(2000)
CSA_L
__delay_cycles(2000)
WR_L
__delay_cycles(2000)
WR_H//数据送入DAC
__delay_cycles(2000)
CSA_H //上升沿数据转高裂李换输出
__delay_cycles(2000)
//NOP_()
}
void B_Dload(int ZZ)
{
data(ZZ)
//__delay_cycles(1)
CSB_L
//__delay_cycles(1) //延时
WR_L
//__delay_cycles(1)
WR_H//数据送入DAC
//__delay_cycles(1)
CSB_H //上升沿数据转换输出
}
int num=17
void key_set(void) //键盘用p5口
{
num=17 //这个num要随戚迟时赋值,否者会和上次的按键值重复
P6DIR=0X0F
P6OUT=0X0e
__delay_cycles(5000)
if(P6IN!=0XF0)
{
__delay_cycles(200000)
if(P6IN!=0XF0)
{
switch(P6IN&0xf0)
{
case 0xe0: num=0while(P6IN&0XF0==0XE0)break
case 0xd0: num=1while(P6IN&0XF0==0Xd0)break
case 0xb0: num=2while(P6IN&0XF0==0Xb0)break
case 0x70: num=3while(P6IN&0XF0==0X70)break
//default:num=17break
}
P6OUT=0X0d
switch(P6IN&0XF0)
{
case 0xe0: num=4while(P6IN&0XF0==0XE0)break
case 0xd0: num=5while(P6IN&0XF0==0Xd0)break
case 0xb0: num=6while(P6IN&0XF0==0Xb0)break
case 0x70: num=7while(P6IN&0XF0==0X70)break
//default:num=17break
}
P6OUT=0X0b
switch(P6IN&0XF0)
{
case 0xe0: num=8while(P6IN&0XF0==0XE0)break
case 0xd0: num=9while(P6IN&0XF0==0XD0)break
case 0xb0: num=10while(P6IN&0XF0==0XB0)break
case 0x70: num=11while(P6IN&0XF0==0X70)break
//default:num=17break
}
P6OUT=0X07
switch(P6IN&0XF0)
{
case 0xe0: num=12while(P6IN&0XF0==0XE0)break
case 0xd0: num=13while(P6IN&0XF0==0XD0)break
case 0xb0: num=14while(P6IN&0X0F0==0XB0)break
case 0x70: num=15while(P6IN&0XF0==0X70)break
// default:num=17break
}
}
}
else num=17
}
#define uint unsigned int
#define uchar unsigned char
#define CS_H (P5DIR|=BIT4,P5OUT|=BIT4)//P1.1
#define CS_L (P5DIR|=BIT4,P5OUT&=~BIT4)//p1.1
#define SID_H (P4DIR|=BIT2,P4OUT|=BIT2)//数据
#define SID_L (P4DIR|=BIT2,P4OUT&=~BIT2)//数据
#define SCLK_H (P4DIR|=BIT3,P4OUT|=BIT3)//P1.3
#define SCLK_L (P4DIR|=BIT3,P4OUT&=~BIT3)//P1.3
void delay_1ms(uint x)
{
uint i,j
for(j=0j<xj++)
for(i=0i<110i++)
}
//////////////////////////////////////
void send_command(uchar command_data)
{
uchar i
uchar i_data
i_data=0xf8
CS_H
SCLK_L
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
///////
i_data=command_data
i_data&=0xf0
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
///////
i_data=command_data
i_data<<=4
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
CS_L
delay_1ms(1)
}
/////////////////////////////////////////
void send_data(uchar command_data)
{
uchar i
uchar i_data
i_data=0xfa
CS_H
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
////
i_data=command_data
i_data&=0xf0
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
////
i_data=command_data
i_data<<=4
for(i=0i<8i++)
{
if(i_data&0x80)
SID_H
else
SID_L
SCLK_L
SCLK_H
i_data=i_data<<1
}
CS_L
delay_1ms(1)
}
void lcd_init()
{
delay_1ms(100)
send_command(0x30)/*设置8位数据接口,基本指令模式。*/
send_command(0x02)/*清DDRAM*/
send_command(0x06)/*游标及显示右移一位*/
send_command(0x0c)/*整体显示开,游标关,反白关*/
send_command(0x01)/*写入空格清屏幕*/
send_command(0x80)/*设定首次显示位置*/
}
/******在特定位置显示一个字符*********/
void Display_char(uint x,uint y,uint c)//// x为 0 - 7
{
if(y==0)
{
send_command(0x80+x)
send_data(c)
}
if(y==1)
{
send_command(0x90+x)
send_data(c)
}
}
void clc_1_hang(uint y) //y为行
{
uint i
if(y==0)
{
send_command(0x80)
for(i=0i<15i++)
send_data(' ')
}
if(y==1)
{
send_command(0x90)
for(i=0i<7i++)
send_data(' ')
}
}
/******在特定位置显示一个字符串或汉字*********/
void Display_string(uint x,uint y,uchar *temp)
{
uint i=0,j=0
if(y==0)
{
send_command(0x80)
for(i=0i<xi++)
send_data(' ')
for(j=xj<15j++)
{
send_data(temp[j-x])
if(temp[j-x]=='\0')
break
}
}
if(y==1)
{
send_command(0x90)
for(i=0i<xi++)
send_data(' ')
for(j=xj<15j++)
{
send_data(temp[j-x])
if(temp[j-x]=='\0')
break
}
}
}
#include "key.c"
#include "12832.c"
#include "DAC7802.C"
#include "stdio.h"
#include "math.h"
char a0=0,a1=0,a2=0,a3=0
char tem[]
int i=0,num
long int beis,bei
void set_am()
{
lcd_init()
Display_string(0,0,"set_gain ")
Display_string(0,1,"sure:10&back:15")
while(1)
{
key_set()
if(num<=9)
{
switch(i)
{
case 0:
{
a0=num
beis=a0
sprintf(tem,"set_gain:%d ",beis)
Display_string(0,1,tem)
i++
break
}
case 1:
{
a1=num
beis=a0*10+a1
sprintf(tem,"set_gain:%d",beis)
Display_string(0,1,tem)
i++
break
}
case 2:
{
a2=num
beis=a0*100+a1*10+a2
sprintf(tem,"set_gain:%d",beis)
Display_string(0,1,tem)
i++
break
}
case 3:
{
a3=num
beis=a0*1000+a1*100+a2*10+a3
sprintf(tem,"set_gain:%d",beis)
Display_string(0,1,tem)
i++
}
default: break
}
}
if(num==10) //确认键
{
bei=beis*4096/1024
B_Dload(bei)//
sprintf(tem,"gain:%d OK! ",beis)
Display_string(0,1,tem)
i=0
a0=0a1=0a2=0a3=0
while(1)
{
key_set()
if(num==11) //加一键
{
beis++
bei=beis*4096/1024
B_Dload(bei)
sprintf(tem,"gain:%d OK! ",beis)
Display_string(0,1,tem)
}
if(num==12) //减一键
{
beis--
bei=beis*4096/1024
B_Dload(bei)
sprintf(tem,"gain:%d OK! ",beis)
Display_string(0,1,tem)
}
if(num==15)
break
}
lcd_init()
Display_string(0,0," THANK YOU!")
Display_string(0,1,"set_again ")
break
}
if(num==14) //清除键
{
switch(i)
{
case 1:
{
a0=0
beis=0
sprintf(tem,"set_gain:%d ",beis)
Display_string(0,1,tem)
i--
break
}
case 2:
{
a1=0
beis=a0
sprintf(tem,"set_gain:%d",beis)
Display_string(0,1,tem)
i--
break
}
case 3:
{
a2=0
beis=a0*10+a1
sprintf(tem,"set_gain:%d ",beis)
Display_string(0,1,tem)
i--
break
}
case 4:
{
a3=0
beis=a0*100+a1*10+a2
sprintf(tem,"set_gain:%d ",beis)
Display_string(0,1,tem)
i--
break
}
default:break
}
}
}
}
/*void step()
{
lcd_init()
Display_string(0,0,"step +:0 -:1 ")
sprintf(tem,"set_am:%d OK!",beis)
Display_string(0,1,tem)
while(1)
{
num=key_set()
if(num==0)
{
beis++
bei=beis*4096/1000
A_Dload(bei)
sprintf(tem,"set_am:%d OK!",beis)
Display_string(0,1,tem)
}
if(num==1)
{
beis--
bei=beis*4096/1000
A_Dload(bei)
sprintf(tem,"set_am:%d OK!",beis)
Display_string(0,1,tem)
}
}
}*/
重新定义一个变量,当DAC_result变化时告塌,那个变量也变化,然后对那个袜银圆变量再进行处理就可以了。比如:定搏樱义num,当DAC_result变化时,让num随着变,但是二者要对应,输出电压和显示的数值要对应!欢迎分享,转载请注明来源:内存溢出
评论列表(0条)