⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osc.c

📁 基于Mini51板的数字示波器设计
💻 C
字号:
#include "lcd12864.h"
#include "osc.h"
#include "common.h"
#include "dots.h"

unsigned char val_vdiv=2; //Y轴电压标度索引0~5
unsigned char val_tdiv=0; //X轴时间标度索引0~5
unsigned char acdc_flag=0; //交流直流档切换
unsigned char run_flag=0;  //运行停止切换
unsigned char pointxA;
unsigned char pointxB;
unsigned char pointyA;
unsigned char pointyB;
unsigned char xdata da_buffer[DATA_SIZE];
unsigned char da_finish;
char movx=0; //水平移动
char movy=0; //垂直移动

unsigned char code vdiv [] = {1,2,5,10,20,50};//电压标度索引是0到5,实际是0.1到5.0
unsigned char code tdiv [] = {5,10,20,50,100};//扫描时间标度索引是0到5

void disp_ypoint(void)
{
	unsigned char dat[ALL_LINE];
	unsigned char j,i;	
	for(j=0;j<3;j++) {
		for(i=0;i<7;i++) dat[i] = 0; 
		if(j==0) {
			dat[(pointyA-2)/8] |= 0x01<<((pointyA-2)%8);
			dat[(pointyA-1)/8] |= 0x01<<((pointyA-1)%8);
			dat[(pointyA  )/8] |= 0x01<<((pointyA  )%8);
			dat[(pointyA+1)/8] |= 0x01<<((pointyA+1)%8);
			dat[(pointyA+2)/8] |= 0x01<<((pointyA+2)%8);
		
			dat[(pointyB-2)/8] |= 0x01<<((pointyB-2)%8);
			dat[(pointyB-1)/8] |= 0x01<<((pointyB-1)%8);
			dat[(pointyB  )/8] |= 0x01<<((pointyB  )%8);
			dat[(pointyB+1)/8] |= 0x01<<((pointyB+1)%8);
			dat[(pointyB+2)/8] |= 0x01<<((pointyB+2)%8);
		
			/*上下平移标志*/
			if(movy== (HEIGHT/2)) {			
				dat[(HEIGHT/2+4-movy)/8] |= 0x01<<((HEIGHT/2+4-movy)%8);
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
			}
			else if(movy==-(HEIGHT/2)) {
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
				dat[(HEIGHT/2+6-movy)/8] |= 0x01<<((HEIGHT/2+6-movy)%8);
			}
			else {
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
			}						

			/*写LCD,刷新显示*/
			for(i=0;i<ALL_LINE;i++) {
				lcd_cmd_wr(SETY+i,0);
				lcd_cmd_wr(SETX+ZEROX-4,0);
				lcd_data_wr(dat[i],0);
			}
		}
		else if(j==1){
			dat[(pointyA-1)/8] |= 0x01<<((pointyA-1)%8);
			dat[(pointyA  )/8] |= 0x01<<((pointyA  )%8);
			dat[(pointyA+1)/8] |= 0x01<<((pointyA+1)%8);
			dat[(pointyB-1)/8] |= 0x01<<((pointyB-1)%8);
			dat[(pointyB  )/8] |= 0x01<<((pointyB  )%8);
			dat[(pointyB+1)/8] |= 0x01<<((pointyB+1)%8);
		
			/*上下平移标志*/
			dat[(HEIGHT/2+4-movy)/8] |= 0x01<<((HEIGHT/2+4-movy)%8);
			dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
			dat[(HEIGHT/2+6-movy)/8] |= 0x01<<((HEIGHT/2+6-movy)%8);
			
			/*写LCD,刷新显示*/
				for(i=0;i<ALL_LINE;i++) {
				lcd_cmd_wr(SETY+i,0);
				lcd_cmd_wr(SETX+ZEROX-3,0);
				lcd_data_wr(dat[i],0);
			}
		}
		else {
			dat[(pointyA)/8] |= 0x01<<((pointyA)%8);
			dat[(pointyB)/8] |= 0x01<<((pointyB)%8);
		
			/*上下平移标志*/
			if(movy==(HEIGHT/2)) {			
				dat[(HEIGHT/2+4-movy)/8] |= 0x01<<((HEIGHT/2+4-movy)%8);
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
			}
			else if(movy==-(HEIGHT/2)) {
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
				dat[(HEIGHT/2+6-movy)/8] |= 0x01<<((HEIGHT/2+6-movy)%8);
			}
			else {
				dat[(HEIGHT/2+5-movy)/8] |= 0x01<<((HEIGHT/2+5-movy)%8);
			}
			
			/*写LCD,刷新显示*/
			for(i=0;i<ALL_LINE;i++) {
				lcd_cmd_wr(SETY+i,0);
				lcd_cmd_wr(SETX+ZEROX-2,0);
				lcd_data_wr(dat[i],0);
			}
		}
	}
}
//LCD波形显示区
void disp(unsigned char x,unsigned char y,char l)
{
	unsigned char dat[ALL_LINE],j,k;	
	x += ZEROX;	
	y = ZEROY-1-y;//1是修正1行空白行
	dat[0] = 0x10;
	dat[1] = 0x0;
	dat[2] = 0x0;
	dat[3] = 0x0;
	dat[4] = 0x0;
	dat[5] = 0x0;
	dat[6] = 0x40;

	
	if((x+1)%5==0) {
		dat[3] |= 0x20;	/*水平中心线*/
		dat[pointyA/8] |= 0x01<<pointyA%8;	/*水平测量线A*/
		dat[pointyB/8] |= 0x01<<pointyB%8;	/*水平测量线B*/
	}

	/*上下边框格点*/
	//if(((x-ZEROX) ==WIDTH/2-1)||((x-ZEROX)%5==0)||((x-ZEROX) == WIDTH/2+1)) {
	if((x-ZEROX)%5==0) {
		dat[0] |= 0x20;dat[ALL_LINE-1] |= 0x20;
	}	

	/*垂直测量线格点和垂直中心线*/
	if(((x-ZEROX) == pointxA)||((x-ZEROX) == pointxB)||((x-ZEROX) == WIDTH/2)) {
		dat[0] |= 0x10;
		dat[1] |= 0x42;
		dat[2] |= 0x08;
		dat[3] |= 0x21;
		dat[4] |= 0x84;
		dat[5] |= 0x10;
		dat[6] |= 0x42;
	}	

	/*顶端测量线三角符号*/
	if(x-ZEROX==(pointxA-2)) dat[0] |= 0x01;
	if(x-ZEROX==(pointxA-1)) dat[0] |= 0x03;
	if(x-ZEROX==(pointxA  )) dat[0] |= 0x07;	
	if(x-ZEROX==(pointxA+1)) dat[0] |= 0x03;
	if(x-ZEROX==(pointxA+2)) dat[0] |= 0x01;	
	if(x-ZEROX==(pointxB-2)) dat[0] |= 0x01;
	if(x-ZEROX==(pointxB-1)) dat[0] |= 0x03;
	if(x-ZEROX==(pointxB  )) dat[0] |= 0x07;	
	if(x-ZEROX==(pointxB+1)) dat[0] |= 0x03;
	if(x-ZEROX==(pointxB+2)) dat[0] |= 0x01;	

	/*顶端中点左右平移标志*/
	if(movx == (WIDTH/2-1)) {
		if(x-ZEROX==WIDTH/2-movx-1) dat[0] |= 0x07;	
		if(x-ZEROX==WIDTH/2-movx  ) dat[0] |= 0x07;		
		if(x-ZEROX==WIDTH/2-movx+1) dat[0] |= 0x02;	
	}
	else if(movx==-(WIDTH/2-1)) {
		if(x-ZEROX==WIDTH/2-movx-1) dat[0] |= 0x02;	
		if(x-ZEROX==WIDTH/2-movx  ) dat[0] |= 0x07;		
		if(x-ZEROX==WIDTH/2-movx+1) dat[0] |= 0x07;	
	}
	else {
		if(x-ZEROX==WIDTH/2-movx-1) dat[0] |= 0x02;	
		if(x-ZEROX==WIDTH/2-movx) dat[0] |= 0x07;		
		if(x-ZEROX==WIDTH/2-movx+1) dat[0] |= 0x02;	
	} 

	/*左边框*/	
	if(x==ZEROX) {
		dat[0] = 0xf0;
		dat[1] = 0xff;
		dat[2] = 0xff;
		dat[3] = 0xff;
		dat[4] = 0xff;
		dat[5] = 0xff;
		dat[6] = 0x7f;	
	}

	/*左边框上格点*/
	if(x==ZEROX+1) {
		dat[0] |= 0x10;
		dat[1] |= 0x42;
		dat[2] |= 0x08;
		dat[3] |= 0x21;
		dat[4] |= 0x84;
		dat[5] |= 0x10;
		dat[6] |= 0x42;	
	}

	/*右边框*/
	if(x==ZEROX+WIDTH-1) {
		dat[0] = 0xf0;
		dat[1] = 0xff;
		dat[2] = 0xff;
		dat[3] = 0xff;
		dat[4] = 0xff;
		dat[5] = 0xff;
		dat[6] = 0x7f;	
	}

	/*右边框格点*/
	if(x==ZEROX+WIDTH-2) {
		dat[0] |= 0x10;
		dat[1] |= 0x42;
		dat[2] |= 0x08;
		dat[3] |= 0x21;
		dat[4] |= 0x84;
		dat[5] |= 0x10;
		dat[6] |= 0x42;	
	}

	/*波形描点*/
	if(l==0) dat[(y)/8] |= 0x01<<((y)%8);
	else if(l>0) {
		for(j=0;j<l+1;j++) { //+1多描1点,波形更粗壮
			k=((y+j)/8);
			if(k>6) k=6;
			if(k==0) dat[0] |= (0x01<<((y+j)%8))&0xe0;
			else if(k==6) dat[6] |= (0x01<<((y+j)%8))&0x3f;
			else dat[k] |= 0x01<<((y+j)%8);
		}
	}
	else for(j=0;j<(-l)+1;j++) {
		k=((y-j)/8);
		if(k>6) k=6;		
		if(k==0) dat[0] |= (0x01<<((y-j)%8))&0xf0;
		else if(k==6) dat[6] |= (0x01<<((y-j)%8))&0x3f;
		else dat[k] |= 0x01<<((y-j)%8);
	}


	/*写入LCD*/
	if(x<64) {
		for(j=0;j<ALL_LINE;j++) {
			lcd_cmd_wr(SETY+j,0);
			lcd_cmd_wr(SETX+x,0);
			lcd_data_wr(dat[j],0);
		}
	}
	else {
		x-=64;
		for(j=0;j<ALL_LINE;j++) {
			lcd_cmd_wr(SETY+j,1);
			lcd_cmd_wr(SETX+x,1);
			lcd_data_wr(dat[j],1);
		}		
	}
}

void disp_vdiv(void)
{		
	unsigned int tmp;
	
	tmp = vdiv[val_vdiv];
	/*y轴电压标度*/
	lcd12864_put_xystr(0,7,4,Num+(tmp/10)*4);
	lcd12864_put_xystr(5,7,1,Num+10*4);
	lcd12864_put_xystr(7,7,4,Num+(tmp%10)*4);	

	tmp = tdiv[val_tdiv];
	/*x轴时间标度*/
	if(tmp<100) {
		lcd12864_put_clr(23,7,8);
		lcd12864_put_xystr(23,7,4,Num+(tmp/10)*4);
		lcd12864_put_xystr(28,7,1,Num+10*4);
		lcd12864_put_xystr(30,7,4,Num+(tmp%10)*4);	
	}
	else {
		lcd12864_put_clr(23,7,8);
		lcd12864_put_xystr(25,7,4,Num+1*4);
		lcd12864_put_xystr(30,7,4,Num+0*4);	
	}

	/*AC,DC标识*/
	lcd12864_put_xystr(47,7,12,ac_dc+acdc_flag*12);//0=ac,1=dc

	/*RUN,PAUSE标识*/
	lcd12864_put_xystr(60,7,17,run_paus+run_flag*17);//0=run,1=paus

	
	tmp=(pointyB-pointyA)*vdiv[val_vdiv];	
	tmp/=5;

	if(tmp < 100) {
		/*测量电压*/
		lcd12864_put_clr(79,7,11);
		lcd12864_put_xystr(79,7,4,Num + (tmp/10)*4);
		lcd12864_put_xystr(84,7,1,Num + 10*4);
		lcd12864_put_xystr(86,7,4,Num + (tmp%10)*4);	
	}
	else {	
		lcd12864_put_clr(79,7,11);
		lcd12864_put_xystr(79,7,4,Num+ (tmp/100)*4);
		lcd12864_put_xystr(85,7,4,Num+ (tmp/10 %10)*4);	
	}

	
	tmp=50000/(pointxB-pointxA)/tdiv[val_tdiv];	
	seg7_disp(tmp);
	/*测量频率*/
	lcd12864_put_clr(99,7,20);
	if(tmp<10) {
		lcd12864_put_xystr(114,7,4,Num+ (tmp%10)*4);	
	}
	else if(tmp <100) {
		lcd12864_put_xystr(109,7,4,Num+ (tmp/10%10)*4);	
		lcd12864_put_xystr(114,7,4,Num+ (tmp%10)*4);
	} else if(tmp <1000) {
		lcd12864_put_xystr(104,7,4,Num+ (tmp/100)*4);
		lcd12864_put_xystr(109,7,4,Num+ (tmp/10%10)*4);	
		lcd12864_put_xystr(114,7,4,Num+ (tmp%10)*4);	
	}
	else {
		lcd12864_put_xystr(99,7,4,Num+ (tmp/1000)*4);
		lcd12864_put_xystr(104,7,4,Num+ (tmp/100%10)*4);
		lcd12864_put_xystr(109,7,4,Num+ (tmp/10%10)*4);	
		lcd12864_put_xystr(114,7,4,Num+ (tmp%10)*4);	
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -