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

📄 新建 文本文档.txt

📁 基于STM上的122x32液晶显示程序显示图形及汉字
💻 TXT
📖 第 1 页 / 共 2 页
字号:

/*
--------------------------------------------------------------------------------

调用方式:void PutChar0(u8 ch)
函数说明:在右页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
--------------------------------------------------------------------------------
-*/
void PutCharR(u8 ch)
{
  OUTSD(ch);
}

/*
--------------------------------------------------------------------------------

调用方式:void PutChar1(uchar ch)
函数说明:在左页当前地址画一个字节8个点。(内函数,私有,用户不直接调用)
--------------------------------------------------------------------------------
-*/
void PutCharL(u8 ch)
{
  OUTMD(ch);
} 


/*
--------------------------------------------------------------------------------

调用方式:void clrscr(void)
函数说明:清屏
--------------------------------------------------------------------------------
-*/
void clrscr(void)
{
  u8 i;
  u8 page;
  for (page=0;page<4;page++)
  {
  SetPage(page,page);
  SetAddress(0,0);
  for (i=0;i<61;i++){PutCharR(0);PutCharL(0);}
  }
} 


//---------------------------------------------------------------
//---------------------------------------------------------------
//采用zimo2  显示汉字,以汉字的显示方式
//void Draw_word(uchar d_where,uint x_add,bit layer,uchar width)
//d_where表示在码表中第几个汉字,x_add横坐标位置,layer显示的层, width显示的宽度。
//纵向取模,字节倒序
//---------------------------------------------------------------


void Draw_word(u16 d_where,u16 x_add,bool layer,u8 width)
{
  u8 x,address;     //address表示显存的物理地址
  //u8 page=0;	//page表示上下两页
  bool window=FALSE;  //window表示左右两页
//putcharR	//右边
//putcharL	//左边
  d_where=d_where*32;

  for (x=width;x>1;x--)
  {
    if (x_add>60) {window=TRUE;address=x_add%61;}
    else address=x_add;	

    if(layer==0)	//显示一行八个字
	{
	
	SetPage(0,0);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HZ[d_where]);//右边
	else	PutCharL(HZ[d_where]);//左边
	SetPage(1,1);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HZ[d_where+width]);
	else	PutCharL(HZ[d_where+width]);

	}
    else
	{	//显示第二行八个汉字
	SetPage(2,2);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HZ[d_where]);//右边
	else	PutCharL(HZ[d_where]);//左边
	SetPage(3,3);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HZ[d_where+width]);
	else	PutCharL(HZ[d_where+width]);

	}
    x_add++;
   d_where++;
}
}


void Draw_Char(u16 d_where,u16 x_add,bool layer,u8 width)
{
  u8 x,address;     //address表示显存的物理地址
  //u8 page=0;	//page表示上下两页
  bool window=FALSE;  //window表示左右两页
//putcharR	//右边
//putcharL	//左边
  d_where=d_where*16;

  for (x=width;x>1;x--)
  {
    if (x_add>60) {window=TRUE;address=x_add%61;}
    else address=x_add;	

    if(layer==0)	//显示一行八个字
	{
	
	SetPage(0,0);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HC[d_where]);//右边
	else	PutCharL(HC[d_where]);//左边
	SetPage(1,1);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HC[d_where+width]);
	else	PutCharL(HC[d_where+width]);
     
	}
    else
	{	//显示第二行八个汉字
	SetPage(2,2);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HC[d_where]);//右边
	else	PutCharL(HC[d_where]);//左边
	SetPage(3,3);
	SetAddress(address,address);
	if(window==TRUE)PutCharR(HC[d_where+width]);
	else	PutCharL(HC[d_where+width]);

	}
    x_add++;
   d_where++;
    
}
}


	







/*************************************************************************
 * Function Name: main
 * Parameters: none
 *
 * Return: none
 *
 * Description: main
 *
 *************************************************************************/
void main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
                       

#ifdef DEBUG
   debug();
#endif

  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC,
                         ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_GPIOA |
                         RCC_APB2Periph_GPIOB |
                         RCC_APB2Periph_GPIOC,
                         DISABLE);

  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 |
                                GPIO_Pin_7 | GPIO_Pin_9 | GPIO_Pin_10;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_12|
                                GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_13|
                                GPIO_Pin_14| GPIO_Pin_15;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
  LEDsSet(LedState);*/
  

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
  RCC_APB2PeriphResetCmd(RCC_APB2Periph_TIM1,DISABLE);

  
 TIM1_TimeBaseInitStruct.TIM1_Prescaler = 720;  // 10us resolution
  TIM1_TimeBaseInitStruct.TIM1_CounterMode = TIM1_CounterMode_Up;
  TIM1_TimeBaseInitStruct.TIM1_Period = 10000;  // 100 ms
  TIM1_TimeBaseInitStruct.TIM1_ClockDivision = TIM1_CKD_DIV1;
   TIM1_TimeBaseInitStruct.TIM1_RepetitionCounter = 0;
   TIM1_TimeBaseInit(&TIM1_TimeBaseInitStruct);


    TIM1_ClearITPendingBit(TIM1_FLAG_Update);
 
                  
    TIM1_ITConfig(TIM1_FLAG_Update,ENABLE);

    NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 7;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
     NVIC_Init(&NVIC_InitStructure);


       TIM1_Cmd(ENABLE);
  
    NVIC_RESETPRIMASK();
 
  lcdini(); //reset                                                   
  clrscr(); //clr 
  
  while(1)
  {
   Draw_word(0,0,0,16); //
   Draw_word(1,16,0,16); //
   Draw_word(2,0,1,16); //
   Draw_word(3,16,1,16); //
   Draw_Char(18,32,0,8); //
   Draw_Char(18,32,1,8); //
 
   
  }
}


#ifdef  DEBUG
/*******************************************************************************
* Function Name  : assert_failed
* Description    : Reports the name of the source file and the source line number
*                  where the assert_param error has occurred.
* Input          : - file: pointer to the source file name
*                  - line: assert_param error line source number
* Output         : None
* Return         : None
*******************************************************************************/
void assert_failed(u8* file, u32 line)
{ 
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
  }
}
#endif

⌨️ 快捷键说明

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