标题:
基于MSP430的数字存储示波器的设计与实现程序
[打印本页]
作者:
390422202
时间:
2018-11-7 17:32
标题:
基于MSP430的数字存储示波器的设计与实现程序
单片机源程序如下:
/*******************************************
方案1需要按复位键即每次只能采样128次
方案2加一个软件触发,从固定位置触发
各种中断形成一个 循环!!上一个中断完成再触发下一个中断
********************************************/
#include <msp430x16x.h>
#include "math.h"
extern unsigned int N_point; //点数
extern unsigned char M_grade; //阶数
#define PI 3.14159265358979323
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define Num_of_Results 129
#define CPU_F ((double)8000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
float data_R[128]; //实部
float data_I[128]; //虚部
uint N_point=128;
uchar M_grade=7;
uint results[32];
uchar fre[4];
uchar mami[7]={"-0000mv"};
uchar h0[] = {"频率"};
uchar h1[] = {"正在保存...."};
uchar h2[] = {"欢迎使用本示波器"};
uchar h3[] = {"保存等待"};
uchar h4[] = {"不可保存"};
uchar h5[] = {"****************"};
uint count,ad,start,end,biger,longer;
ulong sum,max=0,min=4095,zhi;
uchar index =0,h=1,temp,flag=1,m=0,c=1;
uchar tem=0,num=0;//中断函数中的计数变量,定义成全局
uchar tempH,tempL,color=1;
uint wavey[128];
#define LCD_DataIn P4DIR=0x00 //数据口方向设置为输入
#define LCD_DataOut P4DIR=0xff //数据口方向设置为输出
#define LCD2MCU_Data P4IN
#define MCU2LCD_Data P4OUT
#define LCD_CMDOut P6DIR|=0xFF //P3口的低三位设置为输出
#define LCD_RS_H P6OUT|=BIT3 //P3 .0
#define LCD_RS_L P6OUT&=~BIT3 //P3.0
#define LCD_RW_H P6OUT|=BIT4 //P3.1
#define LCD_RW_L P6OUT&=~BIT4 //P3.1
#define LCD_EN_H P6OUT|=BIT5 //P3.2
#define LCD_EN_L P6OUT&=~BIT5 //P3.2
/*******************************************
函数名称:int_CAP()
功 能:初始化触发器!!只打开触发引脚P13
参 数:无
返回值 :无
********************************************/
void int_CAP()
{
P1SEL = 0x0C;//P12P13作为捕获输入端子
P1DIR = 0x00;
TACCTL1|=CM_2+SCS+CAP;//P12下升沿触发捕获,同步模式 不开中断
TACCTL2|=CM_1+SCS+CAP+CCIE;//P13上升沿触发捕获,同步模式
TACTL|=TASSEL_2+MC_2;//SMCLK作为计数脉冲,不分频
}
/*******************************************
函数名称:Clock_Init()
功 能:初始化时钟
参 数:无
返回值 :无
********************************************/
void Clock_Init() //时钟初始化
{
uchar i;
BCSCTL1&=~XT2OFF; //打开XT振荡器
BCSCTL2|=SELM1+SELS+DIVS_3; //MCLK为8MHZ,SMCLK为1MHZ
do
{
IFG1&=~OFIFG; //清除震荡标志
for(i=0;i<100;i++)
_NOP(); //延时等待
}
while((IFG1&OFIFG)!=0); //如果标志为1,则继续循环等待
IFG1&=~OFIFG;
}
/*******************************************
函数名称:int_adc()
功 能:初始化ADC
参 数:无
返回值 :无
********************************************/
void int_adc()
{
P6SEL |= 0x07; // P6.0 P6.1P6.2ADC option select
P6DIR |=0XF8;
ADC12CTL0 = SHT0_2 + ADC12ON+REF2_5V+REFON+MSH; // Set sampling time, turn on ADC12
ADC12CTL1 = SHP+CONSEQ_3;// Use sampling timer
ADC12MCTL0 = 0X00;//参考电压 AVCC AVSS
ADC12MCTL1 = INCH_1;
ADC12MCTL2 = INCH_2+EOS;//选择通路,EOS停止第一轮转化
ADC12IE = 0x04; //中断最后一个使能 // Enable interrupt
ADC12CTL0 |= ENC; // 转化 enabled
}
/*******************************************
函数名称:Delay_1ms
功 能:延时约1ms的时间
参 数:无
返回值 :无
********************************************/
void Delay_1ms(void)
{
uchar i;
for(i = 150;i > 0;i--) _NOP();
}
/*******************************************
函数名称:fft_128()
功 能:fft变换
参 数:无
返回值 :无
********************************************/
void fft_128()
{ float tab_sin_128[128]={ //正玄表 旋转因子所在
0.0000, 0.0491, 0.0980, 0.1467,0.1951,
0.2430, 0.2903, 0.3369, 0.3827,
0.4276, 0.4714, 0.5141, 0.5556, 0.5957,
0.6344, 0.6716, 0.7071, 0.7410,
0.7730, 0.8032, 0.8315, 0.8577, 0.8819,
0.9040, 0.9239, 0.9415, 0.9569,
0.9700, 0.9808, 0.9892, 0.9952, 0.9988,
1.0000, 0.9988, 0.9952, 0.9892,
0.9808, 0.9700, 0.9569, 0.9415, 0.9239,
0.9040, 0.8819, 0.8577, 0.8315,
0.8032, 0.7730, 0.7410, 0.7071, 0.6716,
0.6344, 0.5957, 0.5556, 0.5141,
0.4714, 0.4276, 0.3827, 0.3369, 0.2903,
0.2430, 0.1951, 0.1467, 0.0980,
0.0491, 0.0000,-0.0491,-0.0980,-0.1467,
-0.1951,-0.2430,-0.2903,-0.3369,
-0.3827,-0.4276,-0.4714,-0.5141,-0.5556,
-0.5957,-0.6344,-0.6716,-0.7071,
-0.7410,-0.7730,-0.8032,-0.8315,-0.8577,
-0.8819,-0.9040,-0.9239,-0.9415,
-0.9569,-0.9700,-0.9808,-0.9892,-0.9952,
-0.9988,-1.0000,-0.9988,-0.9952,
-0.9892,-0.9808,-0.9700,-0.9569,-0.9415,
-0.9239,-0.9040,-0.8819,-0.8577,
-0.8315,-0.8032,-0.7730,-0.7410,-0.7071,
-0.6716,-0.6344,-0.5957,-0.5556,
-0.5141,-0.4714,-0.4276,-0.3827,-0.3369,
-0.2903,-0.2430,-0.1951,-0.1467,
-0.0980,-0.0491};
int i;
int L;// the grade deal with now
int J;//the point deal with now
int B;//蝶形两左翅 相距的距离
int var;//临时变量
int P,Q;//cos sin 在sintab中的位置 旋转因子
float data_R_J,data_I_J,data_R_JB,data_I_JB;//临时变量 存放data_R。。等
for (i=0;i<N_point;i++)
{
data_R[i]=(float)wavey[i];
}
for(L=1;L<=M_grade;L++)//L级
{
B=1;
var=L-1;while(var>0){B=2*B;var--;}//B=2^(L-1);
for(i=0;i<B;i++) // 交叉蝶形中的第i个蝶形 第J=J+2*B个交叉蝶形 因为没两个交叉蝶形相距2*B
{
P=1;var=M_grade-L;
while(var>0){P=2*P;var--;}
P=P*i; //P=J*2^(M-L) ;J=i now
if(P<3*N_point/4)
Q=P+N_point/4;
else Q=P-3*N_point/4;
for(J=i;J<N_point;J=J+2*B)//128 N_point/2 第J个交叉蝶形
{
data_R_J=data_R[J];
data_I_J=data_I[J];
data_R_JB=data_R[J+B];
data_I_JB=data_I[J+B];//
data_R[J]=data_R_J+data_R_JB*tab_sin_128[Q]+data_I_JB*tab_sin_128[P];
data_I[J]=data_I_J+data_I_JB*tab_sin_128[Q]-data_R_JB*tab_sin_128[P];
data_R[J+B]=data_R_J-data_R_JB*tab_sin_128[Q]-data_I_JB*tab_sin_128[P];
data_I[J+B]=data_I_J-data_I_JB*tab_sin_128[Q]+data_R_JB*tab_sin_128[P];
}
}
}
}
/*******************************************
函数名称:Delay_Nms
功 能:延时N个1ms的时间
参 数:n--延时长度
返回值 :无
********************************************/
void Delay_Nms(uint n)
{
uint i;
for(i = n;i > 0;i--) Delay_1ms();
}
/*******************************************
函数名称:Write_Cmd
功 能:向液晶中写控制命令
参 数:cmd--控制命令
返回值 :无
********************************************/
void Write_Cmd(uchar cmd)
{
uchar lcdtemp = 0;
LCD_RS_L;
LCD_RW_H;
LCD_DataIn;
do //判忙
{
LCD_EN_H;
_NOP();
lcdtemp = LCD2MCU_Data;
LCD_EN_L;
}
while(lcdtemp & 0x80);
LCD_DataOut;
LCD_RW_L;
MCU2LCD_Data = cmd;
LCD_EN_H;
_NOP();
LCD_EN_L;
}
/*******************************************
函数名称:Write_Data
功 能:向液晶中写显示数据
参 数:dat--显示数据
返回值 :无
********************************************/
void Write_Data(uchar dat)
{
uchar lcdtemp = 0;
LCD_RS_L;
LCD_RW_H;
LCD_DataIn;
do //判忙
{
LCD_EN_H;
_NOP();
lcdtemp = LCD2MCU_Data;
LCD_EN_L;
}
while(lcdtemp & 0x80);
LCD_DataOut;
LCD_RS_H;
LCD_RW_L;
MCU2LCD_Data = dat;
LCD_EN_H;
_NOP();
LCD_EN_L;
}
uchar readData(void)
{
uchar lcdtemp = 0;
unsigned char RData;
MCU2LCD_Data=0xff;
LCD_RS_L;
LCD_RW_H;
LCD_DataIn;
do //判忙
{
LCD_EN_H;
_NOP();
lcdtemp = LCD2MCU_Data;
LCD_EN_L;
}
while(lcdtemp & 0x80);
LCD_RS_H;
LCD_RW_H;
LCD_EN_L;
LCD_EN_H;
RData=LCD2MCU_Data;
LCD_EN_L;
return RData;
}
/***********************************************************
函数名: drawPoint
函数说明:画点
传入参数:打点位置(x0,y0);color=1,点亮;color=0,擦除
传出参数:无
返回值: 无
**********************************************************/
void Draw_point(unsigned char x,unsigned char y,unsigned char color)
{
uchar row,collum,cbite;
Write_Cmd(0x34);
Write_Cmd(0x36);
collum=x>>4;
cbite=x&0x0f;
if(y<32)
row=y;
else
{row=y-32;
collum+=8;
}
Write_Cmd(0x80+row);
Write_Cmd(0x80+collum);
readData();
tempH=readData();
tempL=readData();
Write_Cmd(0x80+row);
Write_Cmd(0x80+collum);
if (color)
{
if(cbite<8)
{
tempH|=(1<<(7-cbite));
}
else
{
tempL|=(1<<(15-cbite));
}
}
else
{
if(cbite<8)
{
tempH&=~(1<<(7-cbite));
}
else
{
tempL&=~(1<<(15-cbite));
}
}
Write_Data(tempH);
Write_Data(tempL);
Write_Cmd(0x30);
}
/***********************************************************
函数名: drawRowLine
函数说明:画水平线
传入参数:(x0,y0),水平线的起点;(x1,y0)水平线的终点
color=1,点亮;color=0,擦除
传出参数:无
返回值: 无
**********************************************************/
void drawRowLine(uchar x0,uchar y0,uchar x1,uchar color)
{
do
{
Draw_point(x0, y0, color); // 逐点显示,描出垂直线
x0++;
}
while(x1>=x0);
}
/***********************************************************
函数名: drawCollumLine
函数说明:画竖直线
传入参数:(x0,y0),竖直线的起点;(x1,y0)竖直线的终点;
color=1,点亮;color=0,擦除
传出参数:无
返回值: 无
************************************************************/
void drawCollumLine(uchar x0,uchar y0,uchar y1,uchar color)
{
while (y0<=y1)
{
Draw_point(x0,y0,color);
y0++;
}
}
/***********************************************************
函数名: drawLine
函数说明:使用Bresenham法,画任意两点间的直线
传入参数:(x0,y0),竖直线的起点;(x1,y1)竖直线的终点 color=1,点亮;color=0,擦除
传出参数:无
返回值: 无
**********************************************************/
void drawLine(uchar x0,uchar y0,uchar x1,uchar y1,uchar color)
{
uchar tempx,tempy;
if(x0>x1) // 对x0、x1大小进行排列,以便画图
{
tempx = x1;
x1 = x0;
x0 = tempx;
}
if(y0>y1)
{
tempy=y0;
y0=y1;
y1=tempy;
}
int dx; // 直线x轴差值变量
int dy; // 直线y轴差值变量
char dx_sym; // x轴增长方向,为-1时减值方向,为1时增值方向
char dy_sym; // y轴增长方向,为-1时减值方向,为1时增值方向
int dx_2; // dx*2值变量,用于加快运算速度
int dy_2; // dy*2值变量,用于加快运算速度
int di; // 决策变量
dx = x1-x0; // 求取两点之间的差值
dy = y1-y0;
if (dx<0) dx_sym=-1;
else
{
if(dx>0) dx_sym=1;
else
{
drawCollumLine(x0,y0,y1,color);
return;
}
}
if(dy>0) dy_sym=1;
else
{
if(dy<0) dy_sym=-1;
else
{
drawRowLine(x0,y0,x1,color);
return;
}
}
dx=dx_sym*dx;
dy=dy_sym*dy;
dx_2=dx*2;
dy_2=dy*2;
if(dx>=dy)
{
di=dy_2-dx;
while(x0!=x1)
{
Draw_point(x0,y0,color);
x0+=dx_sym;
if(di<0) di+=dy_2;
else {di+=dy_2-dx_2;y0+=dy_sym;}
}
Draw_point(x0,y0,color);
}
else
{
di=dx_2-dy;
while(y0!=y1)
{
Draw_point(x0,y0,color);
y0+=dy_sym;
if(di<0) di+=dx_2;
else {di+=dx_2-dy_2;x0+=dx_sym;}
}
Draw_point(x0,y0,color);
}
}
/*******************************************
函数名称:Disp_HZ
功 能:控制液晶显示汉字
参 数:addr--显示位置的首地址
pt--指向显示数据的指针
num--显示字符个数
返回值 :无
********************************************/
void Disp_HZ(uchar addr,const uchar * pt,uchar num)
{
uchar i;
Write_Cmd(addr);
for(i = 0;i < (num*2);i++)
Write_Data(*(pt++));
}
/****************************
数字
*****************************/
void Disp_SZ(uchar addr,const uchar * pt,uchar num)
{
uchar i;
Write_Cmd(addr);
for(i = 0;i < num;i++)
Write_Data(*(pt++));
}
void Ini_Lcd(void)
{
//LCD_CMDOut; //液晶控制端口设置为输出
// Delay_Nms(500);
Write_Cmd(0x30); //基本指令集
Delay_1ms();
Write_Cmd(0x02); // 地址归位
Delay_1ms();
Write_Cmd(0x0c); //整体显示打开,游标关闭
Delay_1ms();
Write_Cmd(0x01); //清除显示
Delay_1ms(); Write_Cmd(0x06); //游标右移
Delay_1ms();
Write_Cmd(0x80); //设定显示的起始地址
}
/*******************************************
函数名称:Clear_GDRAM
功 能:清除液晶GDRAM中的随机数据
参 数:无
返回值 :无
********************************************/
void Clear_GDRAM()
{
uchar i,j,k;
Write_Cmd(0x34); //打开扩展指令集
i = 0x80;
for(j = 0 ;j < 32;j++)
{
Write_Cmd(i++);
Write_Cmd(0x80);
for(k = 0;k < 16;k++)
{
Write_Data(0x00);
}
}
i = 0x80;
for(j = 0;j < 32;j++)
{
Write_Cmd(i++);
Write_Cmd(0x88);
for(k = 0;k < 16;k++)
{
Write_Data(0x00);
}
}
Write_Cmd(0x30); //回到基本指令集
}
/*******************************************
函数名称:Draw_TX
功 能:显示一个16*16大小的图形
参 数:Yaddr--Y地址
Xaddr--X地址
dp--指向图形数据存放地址的指针
返回值 :无
********************************************/
void Draw_TX(uchar Yaddr,uchar Xaddr,const uchar * dp)
{
uchar j;
uchar k=0;
// Write_Cmd(0x01); //清屏,只能清除DDRAM
Write_Cmd(0x34); //使用扩展指令集,关闭绘图显示
for(j=0;j<16;j++)
{
Write_Cmd(Yaddr++); //Y地址
Write_Cmd(Xaddr); //X地址
Write_Data(dp[k++]);
Write_Data(dp[k++]);
}
Write_Cmd(0x36); //打开绘图显示
// Write_Cmd(0x30); //回到基本指令集模式
}
/*******************************************
函数名称:FRE()
功 能:对定时器内的数据进行处理,得出频率
参 数:
返回值 :无
********************************************/
void choose()
{
zhi = (zhi*3200)/4095;
zhi=zhi/2;
mami[1]=zhi/1000+0X30;
mami[2]=(zhi%1000)/100+0X30;
mami[3]=(zhi%1000)%100/10+0X30;
mami[4]=(zhi%1000)%100%10+0X30;
Disp_SZ(0x8d,mami+1,6);
Disp_SZ(0x98,mami,7);
max=0;
min=4095;
}
/*******************************************
函数名称:FRE()
功 能:对定时器内的数据进行处理,得出频率
参 数:
返回值 :无
********************************************/
void FRE()
{ uint temp2;
uchar temp1;
temp2=1000000/sum;
temp1=temp2/1000;
fre[0]=temp1+0x30;
temp2=temp2-temp1*1000;
temp1=temp2/100;
fre[1]=temp1+0x30;
temp2=temp2-temp1*100;
temp1=temp2/10;
fre[2]=temp1+0x30;
temp2=temp2-temp1*10;
fre[3]=temp2+0x30;
}
/*******************************************
函数名称:COMPA()
功 能:比较器
参 数:
返回值 :无
********************************************/
void COMPA()
{
P2SEL = 0x1c; //P24 P23 P22分别为比较器输入输出
P2DIR = 0x04; //
CACTL1 = CAON+CARSEL+CAREF_0 ; // 使用外部参考电压 一脚可以接地
CACTL2 = P2CA0+P2CA1+CAF; // 使用 CA0 CA1
}
/*******************************************
函数名称:timer()
功 能:计数器处理
参 数:
返回值 :无
********************************************/
void timer()
{
TACCTL1&=~CCIE;
P1IE=(BIT0+BIT4+BIT5+BIT6+BIT7);
flag=0;
tem++;
switch(tem)
{
case 1:{start=TACCR1;}break;
case 2:end=TACCR1;
if(end>start)
{
results[num]=(end-start);
}
else
{
results[num]=(65536-start+end);
}
tem=0;
num++;
break;
}
Delay_1ms();
TACCTL1|=CCIE;//以前是关总中断 现在试试关定时器中断
if(num==32)
{ uchar i;
for(i = 0; i < num; i++)
{
sum+=results[i];
}
sum >>=5;
FRE();
Disp_SZ(0x8A,fre,4);
sum=0;
num=0;
TACCTL1&=~CCIE;
Disp_HZ(0x9c,h3,4);
delay_ms(1000);
Disp_HZ(0x9c,h4,4);
P1IE&=~(BIT0+BIT4+BIT5+BIT6+BIT7);
//ADC12IE |= 0x01;
ADC12CTL0 |= ENC;//只能单位置位
TACCTL2 |=CCIE;
//_EINT();
}
}
/*******************************************
函数名称:Key
功 能:存储
参 数:
返回值 :无
********************************************/
void Key(void)
{
P1DIR&=~(BIT0+BIT4+BIT5+BIT6+BIT7);
P1SEL&=~(BIT0+BIT4+BIT5+BIT6+BIT7);
P1IES = BIT0+BIT4+BIT5+BIT6+BIT7;
}
/*******************************************
函数名称:change
功 能:改变频率和放大倍数
参 数:
返回值 :无
********************************************/
void change()
{
zhi=max-min;
P5SEL = 0X00;
P5DIR = 0XFF;
ADC12CTL0 &= ~ENC;//置位0,DIV才能改
if(longer<512)
{
ADC12CTL1 = ADC12DIV_0+SHP+CONSEQ_3;
}
else if(longer<1024)
{
ADC12CTL1 = ADC12DIV_1+SHP+CONSEQ_3;
}
else if(longer<1536)
{
ADC12CTL1 = ADC12DIV_2+SHP+CONSEQ_3;
}
else if(longer<2048)
{
ADC12CTL1 = ADC12DIV_3+SHP+CONSEQ_3;
}
else if(longer<2560)
{
ADC12CTL1 = ADC12DIV_4+SHP+CONSEQ_3;
}
else if(longer<3072)
{
ADC12CTL1 = ADC12DIV_5+SHP+CONSEQ_3;
}
else if(longer<3584)
{
ADC12CTL1 = ADC12DIV_6+SHP+CONSEQ_3;
}
else if(longer<4096)
{
ADC12CTL1 = ADC12DIV_7+SHP+CONSEQ_3;
}
ADC12CTL0 |= ENC;
////////
if(biger<256)
{
P5OUT = 0x06;
zhi=zhi/156;
}
else if(biger<512)
{
P5OUT = 0x0e;
zhi=zhi/143;
}
else if(biger<786)
{
P5OUT = 0x16;
zhi=(zhi*27)/2600;
}
else if(biger<1024)
{
P5OUT = 0x1e;
zhi=(zhi*8)/1005;
}
else if(biger<1280)
{
P5OUT = 0x26;
zhi=zhi/78;
}
else if(biger<1536)
{
P5OUT = 0x2e;
//zhi=(zhi*9)/435;
}
else if(biger<1792)
{
P5OUT = 0x36;
zhi=(zhi*5)/119;
}
else if(biger<2048)
{
P5OUT = 0x3e;
zhi=(zhi*20)/97;
}
else if(biger<2304)
{
P5OUT = 0x07;
zhi=(zhi*15)/293;
}
else if(biger<2560)
{
P5OUT = 0x0f;
zhi=(zhi*44)/775;
}
else if(biger<2816)
{
P5OUT = 0x17;
zhi=(zhi*90)/1001;
}
else if(biger<3072)
{
P5OUT = 0x1f;
zhi=(zhi*75)/312;
}
else if(biger<3328)
{
P5OUT = 0x27;
zhi=(zhi*5)/48;
}
else if(biger<3584)
{
P5OUT = 0x2f;
zhi=(zhi*700)/4318;
}
else if(biger<3840)
{
P5OUT = 0x37;
zhi=(zhi*100)/322;
}
else if(biger<4096)
{
P5OUT = 0x3f;
zhi=(zhi*1000)/607;
}
}
/*******************************************
函数名称:write_Seg
功 能:存储数据到某段FLASH
参 数:
返回值 :无
********************************************/
void write_Seg (uint add)
{
uchar *Flash_ptr; // Flash pointer
uchar i;
Flash_ptr = (uchar *)add; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY;
// Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment空写
FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
*Flash_ptr++ = wavey[i]; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
/*******************************************
函数名称:read_Seg
功 能:read_某段FLASH
参 数:
返回值 :无
********************************************/
void read_Seg(uint add)
{
uchar *Flash_ptr; // Segment A pointer
uchar i;
Flash_ptr = (uchar *)add;
//FCTL1 = FWKEY + ERASE; // Set Erase bit
//FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment B
//FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
for (i=0; i<128; i++)
{
wavey[i] = *Flash_ptr++;
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY + LOCK; // Set LOCK bit
}
/***************************主函数*************************/
void main( void )
{
P6SEL = 0x00;
LCD_CMDOut;
WDTCTL = WDTPW + WDTHOLD; //关狗
Key();
Clock_Init();
int_adc();
COMPA();
_EINT();
Ini_Lcd(); //初始化液晶
Clear_GDRAM();
Disp_SZ(0x80,h5,16);
Disp_HZ(0x90,h2,8);
Disp_SZ(0x88,h5,16);
delay_ms(1000);
Write_Cmd(0x01); //清除汉字显示
Delay_1ms();
Disp_HZ(0x88,h0,2);
//while(1)
//{
_NOP();
int_CAP(); //波形显示完成后在初始化
// }
// _BIS_SR(CPUOFF + GIE); // LPM0, ADC12_ISR will force exit
//write_Seg(0x1080);
}
/*******************************************
函数名称:ADC中断
功 能:进入中断程序,处理采集到的数据
参 数:
返回值 :无
********************************************/
#pragma vector=ADC_VECTOR // ADC12 interrupt service rout ine
__interrupt void ADC12ISR (void)
{ ADC12IE &= ~ 0x04; // Enable interrupt关中断不可以!!!!!
TACCTL2&=~CCIE;//
uchar y=0;
if(max<ADC12MEM2)
{
max=ADC12MEM2;
}
if(min>ADC12MEM2)
{
min=ADC12MEM2;
}
ad = ADC12MEM2;
biger = ADC12MEM1;
longer = ADC12MEM0;
ad >>=7;
wavey[index++] = ad;
if(index==127)
{
index=0;
ADC12CTL0 &= ~ ADC12SC;
ADC12CTL0 &= ~ENC;//停止转化
Clear_GDRAM();
for (m=0;m<127;m++)
{
uchar Oldx,Oldy ;
Draw_point((m*h),(31*(h-1)/h+wavey[y]/h),1);
Oldx=(uchar)(m*h);
Oldy=(uchar)(31*(h-1)/h+wavey[y]/h);
drawLine(Oldx,Oldy,((m+1)*h+0),(31*(h-1)/h+wavey[++y]/h),1);
}
change();//把转换通道换一下
choose();
TACCTL1|=CCIE;
_NOP();
}
ADC12IE |= 0x04;
}
/*******************************************
函数名称:定时器中断
功 能:读取定时器数据
参 数:
返回值 :无
********************************************/
#pragma vector=TIMERA1_VECTOR
__interrupt void Timer_A(void)
{
switch( TAIV )
{
case 2: {timer();}break;
case 4: ADC12CTL0 |= ADC12SC; break; //重新打开使能 32次转换完成之后再开始ADC
case 10: break;
}
}
#pragma vector=PORT1_VECTOR
__interrupt void KeyBord(void)
{
if((P1IFG&BIT7)!=0)
{
Write_Cmd(0x01); //清除汉字显示
Delay_1ms();
Disp_HZ(0x88,h0,2);
P1IFG&=~BIT5;//清处中断标志
P1IFG&=~BIT6;//清处中断标志
P1IFG&=~BIT7;//清处中断标志
}
else if((P1IFG&BIT5)!=0)
{
Clear_GDRAM();
Write_Cmd(0x01); //清除显示
Delay_1ms();
uchar y=0;
read_Seg(0x1000);
for (m=0;m<127;m++)
{
uchar Oldx,Oldy ;
Draw_point((m*h),(31*(h-1)/h+wavey[y]/h),1);
Oldx=(uchar)(m*h);
Oldy=(uchar)(31*(h-1)/h+wavey[y]/h);
drawLine(Oldx,Oldy,((m+1)*h+0),(31*(h-1)/h+wavey[++y]/h),1);
}
}
else if((P1IFG&BIT6)!=0)
{ Clear_GDRAM();
Write_Cmd(0x01); //清除显示
Delay_1ms();
uchar y=0;
read_Seg(0x1080);
for (m=0;m<127;m++)
{
uchar Oldx,Oldy ;
Draw_point((m*h),(31*(h-1)/h+wavey[y]/h),1);
Oldx=(uchar)(m*h);
Oldy=(uchar)(31*(h-1)/h+wavey[y]/h);
drawLine(Oldx,Oldy,((m+1)*h+0),(31*(h-1)/h+wavey[++y]/h),1);
}
}
else if((P1IFG&BIT4)!=0)
{
Clear_GDRAM();
Write_Cmd(0x01); //清除显示
Delay_1ms();
Disp_HZ(0x80,h1,6);
if(c==1)
{
write_Seg (0x1000);
c=2;
}
else if(c==2)
{
write_Seg (0x1080);
c=1;
}
//Disp_HZ(0x88,h2,8);
delay_ms(1000);
Write_Cmd(0x01); //清除汉字显示
Delay_1ms();
Disp_HZ(0x88,h0,2);
P1IFG&=~BIT4;//清处中断标志
} else if((P1IFG&BIT0)!=0)
{
Clear_GDRAM();
Write_Cmd(0x01); //清除显示
Delay_1ms();
int i;
for(i=0;i<N_point;i++)
{
data_I[i]=0;
}
fft_128();
for(i=0;i<128;i++)
{
wavey[i]=(unsigned int)sqrt(data_R[i]*data_R[i]+data_I[i]*data_I[i])/32;
}
for(i=0;i<128;i++)
{ //drawCollumLine(i,(31*(h-1)/h+wavey[i]/h),31,1);
Draw_point(i,1,1);
Draw_point(i,(31*(h-1)/h+wavey[i]/h),1);
drawLine(i,(31*(h-1)/h+wavey[i]/h),i,1,1);
}
_NOP();
delay_ms(1000);
Disp_HZ(0x88,h0,2);
P1IFG&=~BIT0;//清处中断标志
}
}
复制代码
所有资料51hei提供下载:
基于MSP430的数字存储示波器的设计与实现程序.docx
(22.28 KB, 下载次数: 14)
2018-11-7 17:31 上传
点击文件名下载附件
下载积分: 黑币 -5
作者:
admin
时间:
2018-11-8 03:08
补全原理图或者详细说明一下电路连接即可获得100+黑币
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1