|
发现用msp430做简易示波器的不多,感觉430还不错
msp430转换速率200KSPS,2系列16M,算是比较快的了吧,用的msp430f2274做的
因为硬件比较简单,基本上是最小系统,程序应该通用的
屏幕12864 (ST7920) 19264(KS0108),程序写的很乱,功能不全,但基本功能有了,而且基本上是东挪西借,呵呵
原理图没有画,前级衰减画上了,但没有装,直接进单片机。
没有画原理图,基本上是最小系统
LCD接口定义和按键都可以在程序中看出来原理图没有画,前级衰减画上了,但没有装,直接进单片机。
没有画原理图,基本上是最小系统
LCD接口定义和按键都可以在程序中看出来
开发工具用的ez430f2013。SPY-BI-WIRE,两线制JTAG,下载比较方便,呵呵
跟1系列区别应该不大,就是频率高点,一些外设不一样而已
12864液晶的主程序部分预览:
- #include<msp430f2274.h>
- #include"math.h"
- #include"font 3X6.h"
- #include"12864.c"
- #define S1 7
- #define S2 6
- #define S3 5
- #define S4 4
- #define S5 3
- #define Num_of_Results 100
- static unsigned int results[Num_of_Results];
- unsigned char index = 0;
- void ADC_Init(void)
- {
- ADC10CTL1 = INCH_7 + CONSEQ_2; //Repeat single channel
- ADC10CTL0 = ADC10SHT_3 + MSC + ADC10ON + ADC10IE; //ADC10ON , Interrupt enale
- ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
- ADC10AE0 |= 0X80;
- }
- /*******************测量电压峰峰值********************/
- void Disp_Vpp(unsigned char hang,unsigned char lie,unsigned int VPP)
- {
- float real_vpp;
- unsigned int Uintvpp;
- unsigned char ge,shi,bai; //,i;
- real_vpp = (VPP*3.3)/1024;
- Uintvpp = real_vpp*100;
- bai = Uintvpp/100%10;
- shi = Uintvpp/10%10;
- ge = Uintvpp%10;
-
- Draw_Font(hang,lie+0,font3x6+9+bai*3);
- Draw_Font(hang,lie+3,font3x6+3);
- Draw_Font(hang,lie+6,font3x6+9+shi*3);
- Draw_Font(hang,lie+10,font3x6+9+ge*3);
-
- }
- void Measure_Vol(void)
- {
- unsigned int Max_voltage = 0,Min_voltage = 1024;
- unsigned int c;
- // float Real_Voltage;
- uchar i,e;
-
- for(i=0;i<100;i++)
- {
- if(results[i] > Max_voltage)
- Max_voltage = results[i];
- else
- if(results[i] < Min_voltage)
- Min_voltage = results[i];
- }
-
- c = Max_voltage - Min_voltage;
- e++;
- if(e > 5)
- {
- Disp_Vpp(10,102,Max_voltage);
- Disp_Vpp(17,102,Min_voltage);
- Disp_Vpp(24,102,c);
- e = 0;
- }
- }
- /********************测量电压峰峰值********************/
- /********************ADC中断服务函数********************/
- #pragma vector = ADC10_VECTOR
- __interrupt void ADC10ISR (void)
- {
- results[index] = ADC10MEM; // Move results
- index++;
- if(index == 100)
- ADC10CTL0 &=~ ADC10IE;
- }
- main()
- {
- uchar y1=0,y2=0,i,j; //y坐标
- uchar TimeDiv = 3;
- WDTCTL = WDTPW + WDTHOLD;
- P1DIR = 0X00; //P1.7--P1.3设为输入,检测按键
- DCOCTL = CALBC1_16MHZ;
- BCSCTL1 = CALBC1_16MHZ;
- Ini_lcd();
- Clear_GDRAM();
- Draw_PM(tab);
- ADC_Init();
- _EINT();
- while(1)
- {
- /**********************检测按键**************************/
- if(!(P1IN&(0x01<<S2)))
- {
- while(!(P1IN&(0x01<<S2)));
- TimeDiv--;
- ADC10CTL0 &=~ ENC;
- ADC10CTL0 = ADC10SHT_0;
- ADC10CTL1 = INCH_7 + CONSEQ_2; //Repeat single channel
- ADC10CTL0 = TimeDiv*0x800 + MSC + ADC10ON + ADC10IE; //ADC10ON , Interrupt enale
- ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
- if(TimeDiv == 0) TimeDiv = 4;
- }
-
- if(index == 100) //测完99次再显示
- {
- index = 0;
- for(i=0;i<=99;i++) //显示时把99次测量的值画点在12864上
- {
- y1 = y2;
- y2 = 61 - (results[i]/17); //17表示 满量程1024除以60个点
- LCD_Set_Dot1(i,y2);
-
- if((abs(y2 - y1)>=3)&&(i!=0)) //如果下一点的纵坐标比前一个点的纵坐标大3,为了看起来连续,两个点画线
- Lcd_DrawLine_Y(y1,y2,i);
- }
- Measure_Vol(); //测量最大值最小值
- Delay_Nms(200); //等待1秒左右时间
- /**********************检测按键S1**************************/
- while(!(P1IN&(0x01<<S1))); // FREEZE,锁定屏幕
- /**********************检测按键S1**************************/
-
- for(i=0;i<=99;i++) //显示过后删除,不能清屏,因为清屏的话看起来屏幕会闪烁
- {
- y1 = y2;
- y2 = 61 - (results[i]/17);
- if((! ((i%10 == 9)&&(y2%10 == 1) ||(i==0) )))
- LCD_ReSet_Dot1(i,y2);
-
- if((abs(y2 - y1)>=3)&&(i!=0))
- Lcd_ReDrawLine_Y(y1,y2,i);
-
- }
-
- for(j=1;j<100;j=j+2) //画中心X,Y轴
- {
- LCD_Set_Dot1(49,j);
- LCD_Set_Dot1(j,31);
- for(i=1;i<62;i=i+10)
- {
- if( ( ((j%10 == 9)||j==1))&&(i%10 == 1) ) //保存背景的点
- LCD_Set_Dot1(j,i);
- }
- }
- ADC10CTL0 |= ADC10IE;
- }
-
- }
- }
复制代码 19264液晶屏:
- #include<msp430f2274.h>
- #include"math.h"
- #include"font 3X6.h"
- #include"19264-KS0108.c"
- #include"ADC.c"
- #define S1 7
- #define S2 6
- #define S3 5
- #define S4 4
- #define S5 3
- void main(void)
- {
- unsigned char y1,y2,i,j;
- P2DIR |= BIT2;
- P3DIR |= BIT0;
- DCOCTL = CALBC1_16MHZ;
- BCSCTL1 = CALBC1_16MHZ;
- WDTCTL = WDTPW + WDTHOLD;
- LCD19264Initial();
- LCD19264Draw_PM(tab);
- ADC_Init();
- _EINT();
-
-
- while(1)
- {
-
- /**********************检测按键S2**************************/
- if(!(P1IN&(0x01<<S2)))
- {
- if(Delay_Time<16384)
- {
- while(!(P1IN&(0x01<<S2)));
- Delay_Time = Delay_Time<<2;
- }
- }
-
- /**********************检测按键S3**************************/
- if(!(P1IN&(0x01<<S3)))
- {
- if(Delay_Time>4)
- {
- while(!(P1IN&(0x01<<S3)));
- Delay_Time = Delay_Time>>2;
- }
- }
-
- /******************************************************************/
- /***************************显示一屏数据***************************/
-
- if(index == Num_of_Results) //在主程序中显示一屏数据
- {
- index = 0;
- for(i=1;i<=Num_of_Results-1;i++)
- {
- y1 = y2;
- y2 = 61 - (results[i]/17);
- LCD19264WriteDot(i,y2,1); //打点
-
- if((abs(y2 - y1) >=3)&(i!=1) ) //为了看起来连续,当y轴间距大于等于3,画线
- {
- LCD19264DrawLine_Y(y1,y2,i,1);
- }
-
- }
-
- /***************************测量最大值,最小值,Vpp并且显示***************************/
-
- Measure_Vol(); //测量最大值最小值
-
- Delay_Nms(500); //延时一段时间,使屏幕变化不那么快
-
- /**********************检测按键S1**************************/
- while(!(P1IN&(0x01<<S1))); // FREEZE,锁定屏幕
- /**********************检测按键S1**************************/
-
- /***************************删除之前显示一屏的数据********************************/
-
- for(i=1;i<=Num_of_Results-1;i++)
- {
- y1 = y2;
- y2 = 61 - (results[i]/17);
- LCD19264WriteDot(i,y2,0);
- if( (abs(y2 - y1) >=3)&(i!=1) ) //因y1初始值为0,有可能比y2小,所以i!=1时画线
- {
- LCD19264DrawLine_Y(y1,y2,i,0);
- }
- }
-
- /***************************显示背景界面的点********************************/
-
- for(i=1;i<162;i+=10)
- {
- for(j=1;j<62;j+=15)
- {
- LCD19264WriteDot(i,j,1);
- }
- }
-
- /***************************显示横轴和纵轴********************************/
-
- for(i=0;i<80;i++)
- {
- LCD19264WriteDot((2*i+1),31,1);
-
- if(i<31)
- LCD19264WriteDot(81,(2*i+1),1);
- }
- ADC10CTL0 |= ADC10IE; //开ADC中断
- }
- _NOP();
- }
- }
复制代码 全部源码下载:
12864 自制版示波器.rar
(85.12 KB, 下载次数: 115)
|
|