m0_52526370
m0_52526370
2021-01-13 11:03

求解决,emwin移植到点阵屏实现温湿度实时显示,屏幕代码如何修改

100
  • c语言
  • visual studio
  1. spi通信已连接,屏幕为128*128的UC1617屏幕,要求能在点阵屏上实时显示,求问如何修改,能解答的大佬还请附上注释

main.c

#include "system.h"
#include "SysTick.h"
#include "led.h"
#include "lcd.h"
#include "usart.h"
#include "stm32f10x_pwr.h"

/*******************************************************************************
* 函 数 名         : RCC_HSE_Config
* 函数功能		   : 自定义系统时钟,可以通过修改PLL时钟源和倍频系数实现时钟调整
* 输    入         : div:RCC_PLLSource_HSE_Div1/RCC_PLLSource_HSE_Div2
					 pllm:RCC_PLLMul_2-RCC_PLLMul_16
* 输    出         : 无
*******************************************************************************/
void RCC_HSE_Config(u32 div,u32 pllm) //自定义系统时间(可以修改时钟)
{
	RCC_DeInit(); //将外设RCC寄存器重设为缺省值
	RCC_HSEConfig(RCC_HSE_ON);//设置外部高速晶振(HSE)
	if(RCC_WaitForHSEStartUp()==SUCCESS) //等待HSE起振
	{
		RCC_HCLKConfig(RCC_SYSCLK_Div1);//设置AHB时钟(HCLK)
		RCC_PCLK1Config(RCC_HCLK_Div2);//设置低速AHB时钟(PCLK1)
		RCC_PCLK2Config(RCC_HCLK_Div1);//设置高速AHB时钟(PCLK2)
		RCC_PLLConfig(div,pllm);//设置PLL时钟源及倍频系数
		RCC_PLLCmd(ENABLE); //使能或者失能PLL
		while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY)==RESET);//检查指定的RCC标志位设置与否,PLL就绪
		RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);//设置系统时钟(SYSCLK)
		while(RCC_GetSYSCLKSource()!=0x08);//返回用作系统时钟的时钟源,0x08:PLL作为系统时钟
	}
}


int main()
{

		RCC_HSE_Config(RCC_PLLSource_HSE_Div2,RCC_PLLMul_9);   //36M();  
    SysTick_Init(36);
    SPI1_Init();
    init();
		delay(100);
    LCD_LIGHT_1;
		

    while(1)
    {
        displaypic();
        delay(500);
        delay(500);
        displayv();
        delay(500);
        delay(500);
        alldisplayon();
        delay(500);
        delay(500);
        displayoff();
        delay(500);
        delay(500);
        displayh();
        delay(500);
        delay(500);
			
				
    }
}

LCD.C

#include "lcd.h"

//UC1617S//

unsigned char static pic[]=
{
   //此处字符串已删除
};


void press()
{
    //while(step);

}


void init()
{

    SPI_NSS_0;
    delay_ms(1); //1ms


    SPI_NSS_1;
	
    delay_ms(500);//Delay more than 150ms.

    write_com(0xe2);//system rest
    delay(30);
		
    write_com(0x24);//SET TEMP        P16  00%
    write_com(0x2b);//panel loading
    write_com(0x2f);//set pump control        ?????????
    write_com(0xeb);//1/12bais  p20  SET  LCD BIAS  RATIO
    write_com(0x81);//set vop 12.7v SET  VBIAS POTENTIOMETER 
    write_com(45);//   p28

    write_com(0xa2);//set line rate               21.1K        P18
    write_com(0xa6);//set inverse display off         p
    write_com(0xc8);//set n_line         inversion            P19
    write_com(0x06);// DISABLE NIV
    write_com(0x89);//set ram adders control              P 17
    write_com(0xc4);//SET LCD MAP CONTROL               p19

    write_com(0x40); //Set Scroll Line LSB 
    write_com(0x50); //Set Scroll Line MSB
    write_com(0xf1);//set com end
    write_com(127);//128com



    write_com(0x84);  //Set Partial Display Control
    write_com(0xad);//set disply enable BW-mode
		
		
		

}



void  setwindowprogram(void)
{
    write_com(0x00); //set page start
    write_com(0x60); //Row start
    write_com(0x70); //Row start

    write_com(0x40);
    write_com(0x50);
    write_com(0x84);

    write_com(0xf4);
    write_com(0x00);//startx
    write_com(0xf5);
    write_com(0x00);//starty
    write_com(0xf6);
    write_com(127);//endx
    write_com(0xf7);
    write_com(127);//endy
    write_com(0xf9);  //?????

}

void displaypic()
{
    int i,j,a=0;
    setwindowprogram();

    for(i=0; i<128; i++)
    {
        for(j=0; j<32; j++)
        {
            write_data(*(pic+(a++)));
					delay_us(10);
        }
    }

}

void displayv()
{
    int i,j,K;
    setwindowprogram();
    for(i=0; i<64; i++)
    {
        for(j=0; j<32; j++)
        {
            write_data(0xff);
        }
        for(K=0; K<32; K++)
        {
            write_data(0x00);
        }
    }
}


void hanzi()
{
    int i,j,a=0;
    write_com(0x00); //set page start
    write_com(0x60); //Row start
    write_com(0x70); //Row start

    write_com(0x40);
    write_com(0x50);
    write_com(0x84);

    write_com(0xf4);
    write_com(0x00);//startx
    write_com(0xf5);
    write_com(0x00);//starty
    write_com(0xf6);
    write_com(27);//endx
    write_com(0xf7);
    write_com(27);//endy
    write_com(0xf9);  //?????

    for(i=0; i<28; i++)
    {
        for(j=0; j<7; j++)
        {
            write_data(*(pic+(a++)));
        }
    }

}




void alldisplayon()
{
    int i,j;
    setwindowprogram();

    for(i=0; i<128; i++)
    {
        for(j=0; j<32; j++)
        {
            write_data(0xff);
        }
    }
}

void displayoff()
{
    int i,j;
    setwindowprogram();
    for(i=0; i<128; i++)
    {
        for(j=0; j<32; j++)
        {
            write_data(0x00);
        }
    }
}

void displayh()
{
    int i,j;
    setwindowprogram();
    for(i=0; i<128; i++)
    {
        for(j=0; j<32; j++)
        {
            write_data(0x33);
        }
    }
}


void write_com(unsigned char Cbyte)
{
    unsigned char i;
    SPI_MISO_0;;
    SPI_CS_0;
    for(i=0; i<8; i++)
    {
        SPI_SCK_0;
			delay_us(1);
        if(Cbyte&0x80)
            SPI_MOSI_1;
        else
            SPI_MOSI_0;
        SPI_SCK_1;
        Cbyte=Cbyte<<1;
				delay_us(5);
    }
    SPI_MISO_1;
		
		
}
void write_data(unsigned char Dbyte)
{
    unsigned char i;

    SPI_MISO_0;
    SPI_CS_1;

    for(i=0; i<8; i++)

    {

        SPI_SCK_0;
        if(Dbyte&0x80)

            SPI_MOSI_1;

        else

            SPI_MOSI_0;
        SPI_SCK_1;

        Dbyte=Dbyte<<1;
				delay_us(5);

    }

    SPI_MISO_1;
}

void delay(int t)
{
    register int i,j;
    for(i=0; i<t; i++)
        for(j=0; j<125; j++);
}










LCD.H

#ifndef _lcd_H
#define _lcd_H

#include "system.h"
#include "SysTick.h"
#include "spi.h"

#define SPI_MISO_1   GPIO_SetBits(GPIOA,GPIO_Pin_6)    //LCD CS = 1
#define SPI_MISO_0   GPIO_ResetBits(GPIOA,GPIO_Pin_6)   //LCD CS = 0
   
#define SPI_CS_1   GPIO_SetBits(GPIOB,GPIO_Pin_0)     //CD
#define SPI_CS_0   GPIO_ResetBits(GPIOB,GPIO_Pin_0)   //CD
   
#define SPI_SCK_1   GPIO_SetBits(GPIOA,GPIO_Pin_5)    //LCD SCL
#define SPI_SCK_0   GPIO_ResetBits(GPIOA,GPIO_Pin_5)   
   
#define SPI_MOSI_1   GPIO_SetBits(GPIOA,GPIO_Pin_7)    //SDA = 1
#define SPI_MOSI_0   GPIO_ResetBits(GPIOA,GPIO_Pin_7)   //SDA = 0
   
#define SPI_NSS_1  GPIO_SetBits(GPIOA,GPIO_Pin_4)    //LCD RST
#define SPI_NSS_0  GPIO_ResetBits(GPIOA,GPIO_Pin_4)   

#define LCD_LIGHT_1  GPIO_SetBits(GPIOA,GPIO_Pin_0)    
#define LCD_LIGHT_0  GPIO_ResetBits(GPIOA,GPIO_Pin_0)  

void init(void);
void alldisplayon(void);
void displayoff(void);
void displaycom(void);
void displayseg(void);
void displaycom1(void);
void displayseg1(void);
void displaysnow(void);
void displayv(void);
void displayh(void);
void delay(int t);
void write_com(unsigned char d);
void write_data(unsigned char d);
void displaypic(void);
void setwindowprogram(void);
void hanzi(void);

#endif

 

  • 点赞
  • 收藏
  • 复制链接分享

3条回答

为你推荐