老铁们可以下载文件,这里不是很清楚
- #include "lcd12864.h"
- void LCD_12864_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PB,PE端口时钟
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12; //LED0-->PB.5 端口配置
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度为50MHz
- GPIO_Init(GPIOA, &GPIO_InitStructure); //根据设定参数初始化GPIOB.5
-
-
- GPIO_SetBits(GPIOA,GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12); //PB.5 输出高
- LCD_PSB_Clr();
- lcd_write_cmd(0x30); //基本指令模式
- lcd_delay(1);
- lcd_write_cmd(0x0c); //开显示,关游标,关反白
- lcd_delay(1);
- lcd_write_cmd(0x01); //清屏
- lcd_delay(1);
- }
- /************lcd12864延时函数*********/
- void lcd_delay (unsigned int xms)
- {
- unsigned int i,j;
- for(i=xms;i>0;i--)
- for(j=110;j>0;j--);
-
- }
- /**********************************************************/
- /*****---------发送一个字节*----------*******/
- /**********************************************************/
- void lcd_sent_beyt(unsigned char date)
- {
- unsigned char i=0;
- for(i=0;i<8;i++)
- {
- if((date<<i)&0x80) LCD_SID_Set(); // SID=1
- else LCD_SID_Clr(); //SID=0
- LCD_SCLK_Clr();//SCLK=0
- LCD_SCLK_Set();//SCLK=1
- }
- lcd_delay(1);
- }
- /**************************************************/
- /*****-----写数据------*******/
- /**************************************************/
- void lcd_write_data(unsigned char date)
- {
- LCD_CS_Set();//CS=1;
- lcd_sent_beyt(0xfa);
- lcd_sent_beyt((date&0xf0));//高4位取出,低四位补0
- lcd_sent_beyt((date<<4)&0xf0);//将所发送字节的低四位移到高四位,低四位自动补0,然后将高四位取出
- lcd_delay(1);//延时1ms 接收处理数据
-
- LCD_CS_Clr();//CS=0
- }
- /**************************************************/
- /****--------写命令---------****/
- /**************************************************/
- void lcd_write_cmd(unsigned char date)
- {
- LCD_CS_Set();
- lcd_sent_beyt(0xf8);
- lcd_sent_beyt(date&0xf0);
- lcd_sent_beyt((date<<4)&0xf0);
- lcd_delay(1);
- LCD_CS_Clr();
- }
- /**************************************************/
- /*******-----------坐标函数-------------**********/
- /**************************************************/
- void LCD_XY(unsigned char X,unsigned char Y)
- {
- unsigned char pos;
- if(X==0)
- {X=0x80;}
- else if(X==1)
- {X=0x90;}
- else if(X==2)
- {X=0x88;}
- else if(X==3)
- {X=0x98;}
- pos=X+Y;
- lcd_write_cmd(pos);
- }
-
- void lcd_clr()
- {
- lcd_write_cmd(0x01); //清除LCD的显示内容
- lcd_delay(1);
- }
- /*************************************************/
- /*-------lcd12864初始化--------*/
- /************************************************/
- void init_12864(void)
- {
- LCD_PSB_Clr();
- lcd_write_cmd(0x30); //基本指令模式
- lcd_delay(1);
- lcd_write_cmd(0x0c); //开显示,关游标,关反白
- lcd_delay(1);
- lcd_write_cmd(0x01); //清屏
- lcd_delay(1);
- }
- /************************************************/
- /*---中英文字符串显示函数----*/
- /************************************************/
- void writestring(unsigned char X,unsigned char Y,unsigned char *p)
- {
-
- LCD_XY(X,Y);
- while(*p!='\0')
- {
-
- lcd_write_data(*p);
- p++;
- if(*p==';')
- break;
- }
- }
- /************************************************/
- /*------字符串显示函数------*/
- /***********************************************/
- void testring(unsigned char *p)
- {
- while(*p!='\0')
- {
-
- lcd_write_data(*p);
- p++;
- }
- }
- /*********************************************/
- /*-------显示函数---------*/
- /***********************************************/
- void xianshi(char X,char Y, unsigned int shu)
- {
- unsigned int i,j,k,l,n;
- i=shu/10000;
- j=(shu-10000*i)/1000;
- k=(shu-10000*i-1000*j)/100;
- l=(shu-10000*i-1000*j-100*k)/10;
- n=shu%10;
- LCD_XY(X,Y);
- if(i!=0)lcd_write_data(i+0x30);
- if((i!=0)||(j!=0))lcd_write_data(j+0x30);
- if((i!=0)||(j!=0)||(k!=0))lcd_write_data(k+0x30);
- if((i!=0)||(j!=0)||(k!=0)||(l!=0))lcd_write_data(l+0x30);
- lcd_write_data(n+0x30);
- testring(" ");
-
- }
- void xiaoshu(char x,char y,float num)
- {
- char aa[10];
- sprintf(aa,"%1.2f",num);
- writestring(x,y,aa);
- }
- //void xianshi_jiao(char X, char Y, int shu)
- //{
- // unsigned int i,j,k,l,n;
- // if(shu>=0)
- // {
- // i=shu/10000;
- // j=(shu-10000*i)/1000;
- // k=(shu-10000*i-1000*j)/100;
- // l=(shu-10000*i-1000*j-100*k)/10;
- // n=shu%10;
- // LCD_XY(X,Y);
- // if(i!=0)lcd_write_data(i+0x30);
- // if((i!=0)||(j!=0))lcd_write_data(j+0x30);
- // if((i!=0)||(j!=0)||(k!=0))lcd_write_data(k+0x30);
- // if((i!=0)||(j!=0)||(k!=0)||(l!=0))lcd_write_data(l+0x30);
- // lcd_write_data(n+0x30);
- // testring(" ");
- // }
- //
- // else
- // {
- // shu=-shu;
- // i=shu/10000;
- // j=(shu-10000*i)/1000;
- // k=(shu-10000*i-1000*j)/100;
- // l=(shu-10000*i-1000*j-100*k)/10;
- // n=shu%10;
- // LCD_XY(X,Y);
- // testring("-");
- // if(i!=0)lcd_write_data(i+0x30);
- // if((i!=0)||(j!=0))lcd_write_data(j+0x30);
- // if((i!=0)||(j!=0)||(k!=0))lcd_write_data(k+0x30);
- // if((i!=0)||(j!=0)||(k!=0)||(l!=0))lcd_write_data(l+0x30);
- // lcd_write_data(n+0x30);
- // testring(" ");
- // }
- //}
复制代码- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "lcd12864.h"
- #include "delay.h"
- #include "led.h"
- #include "dac.h"
- #include "adc.h"
- #include "timer.h"
- #include "dma.h"
- //#include "stdio.h"
- extern __IO uint16_t ADC_ConvertedValue[102];
- __IO uint16_t ADC_Value[3];
- float ADC_ConvertedValueLocal[102];
- float get_mV[3];
- u16 DAC_Value[32]={2500,2500,2500,2500,2500,2500,2500,2500,1500,2500,
- 2600,2600,2600,2600,2600,2600,2600,2600,1600,2600,
- 2400,2400,2400,2400,2400,2400,2400,2400,2400,2440,
- 2500,2500};
- void angler_mV()
- {
- int j;
- static double sum=0;
-
- for(j=0;j<100;j++)
- {
- sum+=ADC_ConvertedValue[j];
- }
- ADC_Value[0]=sum/100;
- sum=0;
- ADC_ConvertedValueLocal[0] = (float)ADC_Value[0]*(3.3/4096);//通道1数据采集
-
- xiaoshu(0,0,ADC_ConvertedValueLocal[0]); //显示采集的电压
- }
- int main(void)
- {
- u16 c;
- float d;
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //中断分组2 delay_init();
-
-
- LCD_12864_Init(); //液晶初始化
- LED_Init(); //LED灯初始化
- TIM3_Int_Init(9,71);
- GPIO_DAC1_Init(); //DAC初始化
- ADC_INIT(); //ADC初始化
- DAC_DMA_Config(DMA1_Channel3,(u32)&DAC->DHR12R1,(u32)DAC_Value,32);//DMA1通道3,
- TIM3->DIER|=1<<8;
- MYDMA_Enable(DMA1_Channel3);
-
- while(1)
- {
- // Dac1_Set_Vol(2500); //设置2.5V
- //
- // DAC_SetChannel1Data(DAC_Align_12b_R, 2000);//设置DAC值
-
- c=DAC_GetDataOutputValue(DAC_Channel_1);//读取前面设置DAC的值
- xianshi(1,4,c);
- d=(float)c*(3.3/4096); //得到DAC电压值
- xiaoshu(1,0, d); //显示采集的电压
- angler_mV();
-
- // LED0=0;
- // delay_ms(200);
- // LED0=1;
- // delay_ms(200);
- }
- }
复制代码
全部资料51hei下载地址:
STM32 12864.7z
(222.77 KB, 下载次数: 104)
|