基于zet6
单片机源程序如下:
- #include "led.h"
- #include "delay.h"
- #include "key.h"
- #include "sys.h"
- #include "lcd.h"
- #include "usart.h"
- #include "adc.h"
- #include "string.h"
- #include "IC.h"
- #include "PWM.h"
- /************************************************
- 库函数版本
- ************************************************/
-
- void show_xy_line(void);
- int q,x,y,y_t,x_t;
- float value[1024];
- int VOLTAGE;
- int vol;
- char show_v[50];
- int y=140;
- int main(void)
- {
- delay_init(); //初始化
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- LED_Init();
- LCD_Init();
- Adc_Init();
- IC_Init() ;
- PWM_Init();
-
-
- PWM_SetPrescaler(72 -1); //Freq = 72M / (PSC + 1) / 100
- PWM_SetCompare1(50); //Duty = CCR / 100
-
-
-
- POINT_COLOR=0xFFFF;
- LCD_DrawLine(5, 260, 240,260);
- LCD_DrawLine(5, 0, 5,260);//x,y轴两直线
- LCD_DrawLine(5, 0, 0,5);
- LCD_DrawLine(5, 0, 10,5);//y轴箭头
- LCD_DrawLine(240, 260, 235,255);
- LCD_DrawLine(240, 260, 235,265);//x轴箭头
-
- while(1)
- {
-
- //数据采集
- for(q=0;q<240;q++)
- {
- value[q]=Get_Adc(ADC_Channel_1);
- delay_us(10);
- }
-
-
- //画图
- LCD_Clear(BLACK);
- show_xy_line();
- LCD_ShowString(5, 261, 60, 16, 16,"VOLTAGE:");
- LCD_ShowString(135, 261, 30, 16, 16,"FRE:");
- // sprintf(show_v,"ADC1_VAL=%f ,ADC1_VOL=%d ",0.005,1);
- // LCD_ShowString(30, 30, 240, 16, 16,show_v);
-
- x_t=5;
- y_t=y;
- for(q=0;q<240;q++)
- {
- value[q]=Get_Adc(ADC_Channel_1);
- x=q+5;
- y=260-value[q]/20;
- LCD_DrawLine(x_t,y_t, x,y);
- x_t=x;
- y_t=y;
- VOLTAGE=100*3.3*value[q]/4095;
- vol = (VOLTAGE%100);
- LCD_ShowNum(67, 261,VOLTAGE/100, 1, 16);
- LCD_ShowString(75, 261, 1, 1, 16,".");
- LCD_ShowxNum(78, 261, vol, 2, 16,0);
- LCD_ShowxNum(178, 261, (IC_GetFreq()+0), 6, 16,0);
- delay_ms(20);
-
- }
- // printf("%f\r\n",value[q]);
-
- //串口发送
- // for(q=0;q<240;q++)
- // {
-
- // printf("(%d,%d)->(%d,%d) %d.%f ->%d.%f\r\n",x,y1,x+1,y2,adcx);
- // printf("%f\r\n",value[q]*3.3/4096);
- // }
-
- LED0=!LED0;
- delay_ms(50);
- }
- }
- void show_xy_line(void)
- {
- POINT_COLOR=0xFFFF;
- BACK_COLOR=0x0000;
- LCD_DrawLine(5, 260, 240,260);
- LCD_DrawLine(5, 0, 5,260);//x,y轴两直线
- LCD_DrawLine(5, 0, 0,5);
- LCD_DrawLine(5, 0, 10,5);//y轴箭头
- LCD_DrawLine(240, 260, 235,255);
- LCD_DrawLine(240, 260, 235,265);//x轴箭头
-
- //LCD_ShowString(8, 510, 200, 16, 16,"0");
- LCD_ShowString(10, 5, 20, 15, 16,"U/V");
- // LCD_ShowString(440, 510, 200, 16, 16,"t/s");
-
- LCD_DrawLine(5, 73, 8,73);
- LCD_DrawLine(5, 135, 8,135);
- LCD_DrawLine(5,198, 8,198);
- //LCD_ShowString(20, 290, 200, 16, 16,"1");//y轴坐标3V处
- // LCD_DrawLine(76, 320, 76,495);
- // LCD_ShowString(74, 510, 200, 16, 16,"2");//x轴坐标2s处
- //LCD_DrawLine(142, 320, 142,495);
- //LCD_ShowString(140, 510, 200, 16, 16,"4");//x轴坐标4s处
- // LCD_DrawLine(208, 320, 208,495);
- //LCD_ShowString(206, 510, 200, 16, 16,"6");//x轴坐标6s处
- // LCD_DrawLine(274, 320, 274,495);
- // LCD_ShowString(272, 510, 200, 16, 16,"8");//x轴坐标8s处
- // LCD_DrawLine(340, 320, 340,495);
- // LCD_ShowString(338, 510, 200, 16, 16,"10");//x轴坐标10s处
- }
复制代码
原理图:无
Keil代码下载:
示波器频率计.rar
(5.58 MB, 下载次数: 28)
|