设计思路:
1,波形在正弦波、锯齿波、方波中可选。
2 ,频率可选范围10Hz-990Hz,由按键阵列手动设置。每次设置时,在0-9的按键阵列中进行选择,按两次按键。例如0+1表示 10Hz,4+3表示430Hz,9+9表示990Hz。每次按键时,由一位数码管显示刚刚按下的按键序号。
3 ,每次在选择波形前,由1602液晶显示器提供文本提示,文本自拟。
4 ,每次在选择频率前,由1602液晶显示器提供文本提示,文本自拟。
5 ,在输出波形时,由1602显示目前的波形种类和频率。
6 ,用两个外部按键中断,一个实现暂停和继续输出波形的功能,另一个实现终止功能并进入下次波形设置。
实现工作流程:
①(开始仿真或按下停止工作按键后)1602提示:请选择波形种类。
② 在按键阵列中按键一次,对应的选择正弦波、锯齿波、方波之一。按键后,数码管显示刚才的按键编号。
③ 1602提示:请设置频率。
④ 在按键阵列中按键两次。输入的两位数,对应10到990Hz。每次按键后,数码管显示刚才的按键编号。
⑤ 通过DAC0832输出波形,在示波器中观察波形。
⑥ 1602显示目前波形的种类和频率。
⑦ 按下暂停按键,输出暂停,1602提示目前为暂停状态。
⑧ 再次按下暂停按键,恢复波形输出,1602继续显示波形的种类和频率。
⑨ 按下终止按键,波形停止输出,回到流程①。
仿真器件:
7SEG-BCD
AT89C51
BUTTON
CAP
CRYSTAL
DAC0832
LM016L
POT-HG
RES
RES16DIPIS
UA741
虚拟仪器模式:OSCILLOSCOPE , AC VOL TMETER
LCD显示部分代码封装:
#include <LCD1602.h>
#include "reg51.h"
sbit RS = P2^6;
sbit RW = P2^5;
sbit EN = P2^7;
//输入:显示行数i,列数j,输出字符,输出字符长度n
void LCD_send(unsigned char i,unsigned char j,unsigned char str[],unsigned char n)
{
unsigned char x=0;
if(i==1)
{write_com(0x80+j);}
else
{write_com(0x80+0x40+j);}
for(x=0;x<n;x++)
{
write_date(str[x]);
delay(150);
}
}
int LCD_init()//初始化函数体
{
EN = 0;
write_com(0X38);//设置16*2显示,5*7点阵,8位数据接口
write_com(0X0C);//设置开显示,不显示光标
write_com(0X06);//写一个字符时,整屏右移
write_com(0X01);//显示清零
return 0;
}
int write_com(unsigned char com)//写命令的函数体
{
RS = 0;
RW = 0;
P0 = com;
delay(5);
EN = 1;
delay(5);
EN = 0;
return 0;
}
int write_date(unsigned char data1)//写数据的函数体
{
RS = 1;
RW = 0;
P0 = data1;
delay(5);
EN = 1;
delay(5);
EN = 0;
return 0;
}
int delay(unsigned char xms)//延时函数
{
unsigned char x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
return 0;
}
键值功能函数部分:
方式一;
void keyscan()//计算键值函数
{
key=0x0f;
if(key!=0x0f)
{
delay(1000);
if(key!=0x0f)
{
key=0x0f;//测试列
switch(key)
{
case(0x07):keyvalue=15;break;
case(0x0b):keyvalue=14;break;
case(0x0d):keyvalue=13;break;
case(0x0e):keyvalue=12;break;
}
key=0xf0;//测试行
if(key!=0xf0)
{
switch(key)
{
case(0x70):keyvalue=keyvalue;break;
case(0xb0):keyvalue=keyvalue-4;break;
case(0xd0):keyvalue=keyvalue-8;break;
case(0xe0):keyvalue=keyvalue-12;break;
}
}
}
while(key!=0xf0) //检测按键松手检测
{
delay(100);
}
switch(keyvalue)
{
case(0):keyd();b=0;C=0;D=0;M=0;break;
case(1):keyd();b=0;C=0;D=0;M=1;break;
case(2):keyd();b=0;C=0;D=1;M=0;break;
case(3):keyd();b=0;C=0;D=1;M=1;break;
case(4):keyd();b=0;C=1;D=0;M=0;break;
case(5):keyd();b=0;C=1;D=0;M=1;break;
case(6):keyd();b=0;C=1;D=1;M=0;break;
case(7):keyd();b=0;C=1;D=1;M=1;break;
case(8):keyd();b=1;C=0;D=0;M=0;break;
case(9):keyd();b=1;C=0;D=0;M=1;break;
case(10):flg=1;LCD_send(1,5,"Sin ",10); //正弦波
LCD_send(2,5,"Select",6);div=0;
b=1;C=0;D=1;M=0;break;
case(11):flg=2;LCD_send(1,5,"Square ",10); //方波
LCD_send(2,5,"Select",6);div=0;
b=1;C=0;D=1;M=1;break;
case(12):flg=3;LCD_send(1,5,"Sawtooth ",10); //锯齿波
LCD_send(2,5,"Select",6);div=0;
b=1;C=1;D=0;M=0;break;
case(13):stop();b=1;C=1;D=0;M=1;z++;break; //暂停
case(14):flg=4;LCD_init();init();b=1;C=1;D=1;M=0;break;;
case(15):b=1;C=1;D=1;M=1;break;
}
}
}
方式二:
uchar keyscan()
{
key=0xef; //判断第一行
if(key!=0xef)
{
delay(100);
switch(key)
{
case 0xee:{keyword=0;keyd();b=0;C=0;D=0;M=0;break;}
case 0xed:{keyword=1;keyd();b=0;C=0;D=0;M=1;break;}
case 0xeb:{keyword=2;keyd();b=0;C=0;D=1;M=0;break;}
case 0xe7:{keyword=3;keyd();b=0;C=0;D=1;M=1;break;}
}
}
key=0xdf; //判断第二行
if(key!=0xdf)
{
delay(100);
switch(key)
{
case 0xde:{keyword=4;b=0;C=1;D=0;M=0;keyd();break;}
case 0xdd:{keyword=5;b=0;C=1;D=0;M=1;keyd();break;}
case 0xdb:{keyword=6;b=0;C=1;D=1;M=0;keyd();break;}
case 0xd7:{keyword=7;b=0;C=1;D=1;M=1;keyd();break;}
}
}
key=0xbf; //判断第三行
if(key!=0xbf)
{
delay(100);
switch(key)
{
case 0xbe:{keyword=8;keyd();b=1;C=0;D=0;M=0;break;}
case 0xbd:{keyword=9;keyd();b=1;C=0;D=0;M=1;break;}
case 0xbb:{
keyword=10;flg=1;TR1=0;LCD_send(1,5,"Sin ",10);LCD_send(2,5,"Select",6);TR1=1;
b=1;C=0;D=1;M=0;break;} //正弦波
case 0xb7:{
keyword=11;flg=2;TR1=0;LCD_send(1,5,"Square ",10);LCD_send(2,5,"Select",6);TR1=1;
b=1;C=0;D=1;M=1;break;} //方波
}
}
key=0x7f; //判断第四行
if(key!=0x7f)
{
delay(100);
switch(key)
{
case 0x7e:{
keyword=12;flg=3;TR1=0;LCD_send(1,5,"Sawtooth ",10);LCD_send(2,5,"Select",6);TR1=1;
b=1;C=1;D=0;M=0;break;} //锯齿波
case 0x7d:{
keyword=13;wr=~wr;b=1;C=1;D=0;M=1;break;} //暂停
case 0x7b:{
keyword=14;flg=4;TR1=0;LCD_send(1,0,"WAVE:Select",11);LCD_send(2,0,"FRE: ",11);TR1=1;
THHL=65536-3906;b=1;C=1;D=1;M=0;break;} //复位终止
case 0x77:{keyword=15;b=1;C=1;D=1;M=1;break;}
}
}
return keyword;
}
注:方式一比方式二多了有松手判断,方式二函数因为定义的数据类型不同可以返回键值keyword
主函数:
void main()
{
LCD_init();
init();
while(1)
{
keyscan();
switch(flg)
{
case 1: DAC0832=sin_tab[n];break; //正弦波
case 2: DAC0832=squ_tab[n];break; //方波
case 3: DAC0832=255-n;break; //锯齿波
case 4: DAC0832=0xff; //复位终止
}
}
}
定时中断函数部分:
void time_intt1(void) interrupt 3
{
TL1=THHL%256;
TH1=THHL/256;
// if(n>=255) {n=0;} else {n++;}
n++;
}
数据段码部分:
unsigned code sin_tab[256]={
0x80,0x83,0x85,0x88,0x8A,0x8D,0x8F,0x92,0x94,0x97,0x99,0x9B,0x9E,0xA0,0xA3,0xA5,0xA7,0xAA,0xAC,0xAE,0xB1,0xB3,0xB5,0xB7,0xB9,0xBB,
0xBD,0xBF,0xC1,0xC3,0xC5,0xC7,0xC9,0xCB,0xCC,0xCE,0xD0,0xD1,0xD3,0xD4,0xD6,0xD7,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,0xE2,
0xE3,0xE3,0xE4,0xE4,0xE5,0xE5,0xE6,0xE6,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE6,0xE6,0xE5,0xE5,0xE4,0xE4,0xE3,0xE3,0xE2,0xE1,
0xE0,0xDF,0xDE,0xDD,0xDC,0xDB,0xDA,0xD8,0xD7,0xD6,0xD4,0xD3,0xD1,0xD0,0xCE,0xCC,0xCB,0xC9,0xC7,0xC5,0xC3,0xC1,0xBF,0xBD,0xBB,0xB9,
0xB7,0xB5,0xB3,0xB1,0xAE,0xAC,0xAA,0xA7,0xA5,0xA3,0xA0,0x9E,0x9B,0x99,0x97,0x94,0x92,0x8F,0x8D,0x8A,0x88,0x85,0x83,0x80,0x7D,0x7B,
0x78,0x76,0x73,0x71,0x6E,0x6C,0x69,0x67,0x65,0x62,0x60,0x5D,0x5B,0x59,0x56,0x54,0x52,0x4F,0x4D,0x4B,0x49,0x47,0x45,0x43,0x41,0x3F,
0x3D,0x3B,0x39,0x37,0x35,0x34,0x32,0x30,0x2E,0x2D,0x2C,0x2A,0x29,0x28,0x26,0x25,0x24,0x23,0x22,0x21,0x20,0x1F,0x1E,0x1D,0x1D,0x1C,
0x1C,0x1B,0x1B,0x1A,0x1A,0x1A,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x1A,0x1A,0x1A,0x1B,0x1B,0x1C,0x1C,0x1D,0x1D,0x1E,0x1F,0x20,
0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2A,0x2C,0x2D,0x2F,0x30,0x32,0x34,0x35,0x37,0x39,0x3B,0x3D,0x3F,0x41,0x43,0x45,0x47,0x49,
0x4B,0x4D,0x4F,0x52,0x54,0x56,0x59,0x5B,0x5D,0x60,0x62,0x65,0x67,0x69,0x6C,0x6E,0x71,0x73,0x76,0x78,0x7B,0x7D};//正弦波段码
unsigned code squ_tab[256]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,};//方波段码
初始化部分:
void init()//初始化
{
THHL=65536-3906;
TH1=THHL/256;
TL1=THHL%256;
TMOD=0x11;
ET1=1;
TR1=1;
EA=1;
wr=0;
b=0;
C=0;
D=0;
M=0;
}
仿真图:
实现效果视频:
完整程序:
#include <reg51.h>
#define uchar unsigned char
#define uint unsigned int
#define key P1
#define DAC0832 P3
sbit b = P2^0;
sbit C = P2^1;
sbit D = P2^2;
sbit M = P2^3; //LCD的BCD码输入口
sbit wr = P2^4; //暂停口
sbit RW = P2^5;
sbit RS = P2^6;
sbit EN = P2^7;
uchar flg = 0; //波形功能判断标志位
uchar keyvalue=16; //键值
uchar n=0;
uchar z=1;
uchar fre[11] ="000Hz ";
uint div=0;
uint data THHL=65536-3906; //初始频率为1Hz
uint write_com(unsigned char); //声明写命令函数
uint write_date(unsigned char); //声明写数据函数
void LCD_send(uchar i,uchar j,uchar str[],uchar n);//声明LCD封装函数
unsigned code sin_tab[256]={
0x80,0x83,0x85,0x88,0x8A,0x8D,0x8F,0x92,0x94,0x97,0x99,0x9B,0x9E,0xA0,0xA3,0xA5,0xA7,0xAA,0xAC,0xAE,0xB1,0xB3,0xB5,0xB7,0xB9,0xBB,
0xBD,0xBF,0xC1,0xC3,0xC5,0xC7,0xC9,0xCB,0xCC,0xCE,0xD0,0xD1,0xD3,0xD4,0xD6,0xD7,0xD8,0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1,0xE2,
0xE3,0xE3,0xE4,0xE4,0xE5,0xE5,0xE6,0xE6,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE7,0xE6,0xE6,0xE5,0xE5,0xE4,0xE4,0xE3,0xE3,0xE2,0xE1,
0xE0,0xDF,0xDE,0xDD,0xDC,0xDB,0xDA,0xD8,0xD7,0xD6,0xD4,0xD3,0xD1,0xD0,0xCE,0xCC,0xCB,0xC9,0xC7,0xC5,0xC3,0xC1,0xBF,0xBD,0xBB,0xB9,
0xB7,0xB5,0xB3,0xB1,0xAE,0xAC,0xAA,0xA7,0xA5,0xA3,0xA0,0x9E,0x9B,0x99,0x97,0x94,0x92,0x8F,0x8D,0x8A,0x88,0x85,0x83,0x80,0x7D,0x7B,
0x78,0x76,0x73,0x71,0x6E,0x6C,0x69,0x67,0x65,0x62,0x60,0x5D,0x5B,0x59,0x56,0x54,0x52,0x4F,0x4D,0x4B,0x49,0x47,0x45,0x43,0x41,0x3F,
0x3D,0x3B,0x39,0x37,0x35,0x34,0x32,0x30,0x2E,0x2D,0x2C,0x2A,0x29,0x28,0x26,0x25,0x24,0x23,0x22,0x21,0x20,0x1F,0x1E,0x1D,0x1D,0x1C,
0x1C,0x1B,0x1B,0x1A,0x1A,0x1A,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x19,0x1A,0x1A,0x1A,0x1B,0x1B,0x1C,0x1C,0x1D,0x1D,0x1E,0x1F,0x20,
0x21,0x22,0x23,0x24,0x25,0x26,0x28,0x29,0x2A,0x2C,0x2D,0x2F,0x30,0x32,0x34,0x35,0x37,0x39,0x3B,0x3D,0x3F,0x41,0x43,0x45,0x47,0x49,
0x4B,0x4D,0x4F,0x52,0x54,0x56,0x59,0x5B,0x5D,0x60,0x62,0x65,0x67,0x69,0x6C,0x6E,0x71,0x73,0x76,0x78,0x7B,0x7D};//正弦波段码
unsigned code squ_tab[256]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,};//方波段码
void stop()
{
if (z%2==1){wr=1;LCD_send(2,5,"stop ",11);}
else{wr=0;LCD_send(2,5,fre,11);}
}
void keyd()
{
if(div<100){div*=10;div+=keyvalue%10;THHL=65536-3906/div;}
if(div>=100){div=0;THHL=65536-3906;}
fre[0]=div/10%10 + '0';fre[1]=div%10 + '0';fre[2]='0';
LCD_send(2,5,fre,11);
}
void delay(uchar xms)//延时函数
{
uchar x,y;
for(x=xms;x>0;x--)
for(y=110;y>0;y--);
}
void init()//初始化
{
THHL=65536-3906;TH1=THHL/256;TL1=THHL%256;
TMOD=0x11;ET1=1;TR1=1;EA=1;wr=0;
b=0;C=0;D=0;M=0;
}
void LCD_send(uchar i,uchar j,uchar str[],uchar n)//输入:显示行数i,列数j,输出字符,输出字符长度n
{
uchar x=0;
if(i==1)
{write_com(0x80+j);}
else
{write_com(0x80+0x40+j);}
for(x=0;x<n;x++)
{
write_date(str[x]);
delay(150);
}
}
void LCD_init()//LCD初始化函数体
{
EN = 0;
write_com(0X38);//设置16*2显示,5*7点阵,8位数据接口
write_com(0X0C);//设置开显示,不显示光标
write_com(0X06);//写一个字符时,整屏右移
write_com(0X01);//显示清零
LCD_send(1,0,"WAVE:Select ",15);
LCD_send(2,0,"FRE: ",15);
}
uint write_com(uchar com)//写命令的函数体
{
RS = 0;
RW = 0;
P0 = com;
delay(5);
EN = 1;
delay(5);
EN = 0;
return 0;
}
uint write_date(uchar data1)//写数据的函数体
{
RS = 1;
RW = 0;
P0 = data1;
delay(5);
EN = 1;
delay(5);
EN = 0;
return 0;
}
void keyscan()//键值功能判断
{
key=0x0f;
if(key!=0x0f)
{
delay(1000);
if(key!=0x0f)
{
key=0x0f;//测试列
switch(key)
{
case(0x07):keyvalue=15;break;
case(0x0b):keyvalue=14;break;
case(0x0d):keyvalue=13;break;
case(0x0e):keyvalue=12;break;
}
key=0xf0;//测试行
if(key!=0xf0)
{
switch(key)
{
case(0x70):keyvalue=keyvalue;break;
case(0xb0):keyvalue=keyvalue-4;break;
case(0xd0):keyvalue=keyvalue-8;break;
case(0xe0):keyvalue=keyvalue-12;break;
}
}
}
while(key!=0xf0) //检测按键松手检测
{
delay(100);
}
switch(keyvalue)
{
case(0):keyd();b=0;C=0;D=0;M=0;break;
case(1):keyd();b=0;C=0;D=0;M=1;break;
case(2):keyd();b=0;C=0;D=1;M=0;break;
case(3):keyd();b=0;C=0;D=1;M=1;break;
case(4):keyd();b=0;C=1;D=0;M=0;break;
case(5):keyd();b=0;C=1;D=0;M=1;break;
case(6):keyd();b=0;C=1;D=1;M=0;break;
case(7):keyd();b=0;C=1;D=1;M=1;break;
case(8):keyd();b=1;C=0;D=0;M=0;break;
case(9):keyd();b=1;C=0;D=0;M=1;break;
case(10):flg=1;LCD_send(1,5,"Sin ",10); //正弦波
LCD_send(2,5,"Select",6);div=0;
b=1;C=0;D=1;M=0;break;
case(11):flg=2;LCD_send(1,5,"Square ",10); //方波
LCD_send(2,5,"Select",6);div=0;
b=1;C=0;D=1;M=1;break;
case(12):flg=3;LCD_send(1,5,"Sawtooth ",10); //锯齿波
LCD_send(2,5,"Select",6);div=0;
b=1;C=1;D=0;M=0;break;
case(13):stop();b=1;C=1;D=0;M=1;z++;break; //暂停
case(14):flg=4;LCD_init();init();b=1;C=1;D=1;M=0;break;;
case(15):b=1;C=1;D=1;M=1;break;
}
}
}
void main()
{
LCD_init();
init();
while(1)
{
keyscan();
switch(flg)
{
case 1: DAC0832=sin_tab[n];break; //正弦波
case 2: DAC0832=squ_tab[n];break; //方波
case 3: DAC0832=255-n;break; //锯齿波
case 4: DAC0832=0xff; //复位终止
}
}
}
void time_intt1(void) interrupt 3
{
TL1=THHL%256;
TH1=THHL/256;
// if(n>=255) {n=0;} else {n++;}
n++;
}
Comments NOTHING