找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2417|回復(fù): 2
收起左側(cè)

基于戰(zhàn)艦STM32的1602液晶驅(qū)動(dòng)程序

[復(fù)制鏈接]
ID:225299 發(fā)表于 2017-8-6 21:01 | 顯示全部樓層 |閱讀模式
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "led.h"
#include "lcd1602.h"
#include "pwm_output.h"
#include "pwm_output.c"
#define KEY1  GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_10)//讀取按鍵0
#define KEY2  GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)//讀取按鍵1
#define KEY3  GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_2)//讀取按鍵2
#define KEY4   GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_11)//讀取按鍵3(WK_UP)
#define KEY5   GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_1)//讀取按鍵3(WK_UP)
void KEY_Init(void) //IO初始化
{
     GPIO_InitTypeDef GPIO_InitStructure;
     /*開啟按鍵端口(PC)時(shí)鐘*/
         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
         GPIO_InitStructure.GPIO_Pin= GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_13;//KEY0-KEY2;
                                GPIO_InitStructure.GPIO_Mode= GPIO_Mode_IPU;
         GPIO_Init(GPIOC,&GPIO_InitStructure);
}
/* 按鍵,彈起有效*/
void KEY_Scan(u8 mode)
{      

         static u8 key_up=1;//???????
         if(mode)
                   key_up=1;  //????           

         if((KEY1==0||KEY2==0||KEY3==0||KEY4==0||KEY5==0))
         {
                   delay_ms(10);//???
                   key_up=0;
                   if(KEY1==0)
                   {
                            KEY1_flag=1;

                            if(0== KEY1_press_flag)
                            {
                                     KEY1_Event_exec_flag= 0;
                                     KEY1_press_flag= 1;
                            }
                   }

                   if(KEY2==0)
                   {
                            KEY2_flag=1;

                            if(0== KEY2_press_flag)
                            {
                                     KEY2_Event_exec_flag= 0;
                                     KEY2_press_flag= 1;
                            }
                   }

                   if(KEY3==0)
                   {
                            KEY3_flag=1;

                            if(0== KEY3_press_flag)
                            {
                                     KEY3_Event_exec_flag= 0;
                                     KEY3_press_flag= 1;
                            }
                   }


                   if(KEY4==0)
                   {
                            if(0== KEY4_flag)
                            {
                                     KEY4_flag=1;
                            }

                            if(0== KEY4_press_flag)
                            {
                                     KEY4_Event_exec_flag= 0;
                                     KEY4_press_flag= 1;
                            }
                   }

                   if(KEY5==0)
                            KEY5_flag=1;
         }

         if((KEY1==1||KEY2==1||KEY3==1||KEY4==1||KEY5==1))
         {
                   delay_ms(10);//???
                   key_up=0;

                   if(KEY1==1)
                   {
                            KEY1_flag=0;

                            if(KEY1_press_flag == 1)
                            {
                                     KEY1_press_flag= 0;

                                     if(0== KEY1_Event_exec_flag)
                                               KEY1_Event_exec_flag= 1;
                            }
                   }

                   if(KEY2==1)
                   {
                            KEY2_flag=0;

                            if(KEY2_press_flag== 1)
                            {
                                     KEY2_press_flag= 0;

                                     if(0== KEY2_Event_exec_flag)
                                               KEY2_Event_exec_flag= 1;
                            }
                   }

                   if(KEY3==1)
                   {
                            KEY3_flag=0;

                            if(KEY3_press_flag== 1)
                            {
                                     KEY3_press_flag= 0;

                                     if(0== KEY3_Event_exec_flag)
                                               KEY3_Event_exec_flag= 1;
                            }
                   }

                   if(KEY4==1)
                   {
                            if(1== KEY4_flag)
                            {                                   
                                     KEY4_flag=0;
                            }

                            if(KEY4_press_flag== 1)
                            {
                                     KEY4_press_flag= 0;

                                     if(0== KEY4_Event_exec_flag)
                                               KEY4_Event_exec_flag= 1;
                            }
                   }

                   if(KEY5==1)
                            KEY5_flag=0;
         }
}
int main(void)
{
        u8 str[] = "ATOM@ALIENTEK";
       
        delay_init();
        NVIC_Configuration();
        uart_init(9600);
        GPIO_Configuration();
        LED_Init();
        LCD1602_Init();
        /* TIM3 PWM波輸出初始化,并使能TIM3 PWM輸出 */
        TIM3_PWM_Init();
        LCD1602_Show_Str(1, 0, str);
        LCD1602_Show_Str(2, 1, "I love STM32");
        while(1)
        {
                LED0 = 0;
                delay_ms(200);
                LED0 = 1;
                delay_ms(200);
        }
}


回復(fù)

使用道具 舉報(bào)

ID:225299 發(fā)表于 2017-8-6 21:02 | 顯示全部樓層
只是主函數(shù)的內(nèi)容,有需要的直接回復(fù)我就好
回復(fù)

使用道具 舉報(bào)

ID:253166 發(fā)表于 2017-11-24 18:40 | 顯示全部樓層
123456WH 發(fā)表于 2017-8-6 21:02
**** 作者被禁止或刪除 內(nèi)容自動(dòng)屏蔽 ****

樓主麻煩你給我發(fā)一份  急用  謝謝  201926154@qq.com
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表