新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > STM32 1602程序

        STM32 1602程序

        作者: 時間:2012-09-10 來源:網絡 收藏

        標 注:用到了 PD_0—7,給PO口(單片機板液晶數據口),PA0_2;

        本文引用地址:http://www.104case.com/article/148438.htm

        已在函數中將他們以寄存器形式配置,注踏出再次配置PD時

        不應在配置這些口;

        在主函數中需將PD,PA使能。

        頭函數:#include1602.h

        函 數:在1602.h中有列舉;

        返回值:無;

        用PD0_7給液晶數據,PA0_2位控制為依次rs,rw,en;

        #ifndef __1602_H

        #define __1602_H

        #include stm32f10x.h

        void write1602_com(u8 com);

        void write1602_dat(u8 dat);

        void lcd1602_init(void);

        void write1602_Achar(u8 hang,u8 numadd,u8 x);

        void write1602_string(u8 hang,u8 numadd,u8 *p);

        #endif

        #includestm32f10x.h

        #include1602.h

        //sbit rs=P2^5;//gpioa_0

        //sbit rw=P2^6;//gpioa_1

        //sbit en=P2^7;//gpioa_2

        void Delayms(unsigned short time)//nms

        {

        unsigned short i, j;

        for(; time > 0; time--){

        for(j = 0; j 10; j++){

        for(i = 0; i 1000; i++);

        }

        }

        }

        void write1602_com(u8 com)

        {

        GPIOD->ODR=0xff00;//??

        GPIOA->ODR=0xfffb;//GPIOA->ODR=02;/

        void RCC_Configuration(void);

        void GPIO_Configuration(void);

        void NVIC_Configuration(void);

        u8 table[]=2010-4-30;

        void Delay(unsigned short time)//nms

        {

        unsigned short i, j;

        for(; time > 0; time--){

        for(j = 0; j 10; j++){

        for(i = 0; i 1000; i++);

        }

        }

        }

        int main(void)

        {

        u8 i;

        RCC_Configuration();

        NVIC_Configuration();

        GPIO_Configuration();

        lcd1602_init();

        while (1)

        {

        //i=Keyscan();

        //Led(i);

        write1602_string(1,17,table);

        for(i=0;i16;i++)

        {

        write1602_com(0x18);

        Delay(200);

        }

        }

        }

        void RCC_Configuration(void)

        {

        RCC_DeInit();

        RCC_HSEConfig(RCC_HSE_ON);

        HSEStartUpStatus = RCC_WaitForHSEStartUp();

        if(HSEStartUpStatus == SUCCESS)

        {

        FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

        FLASH_SetLatency(FLASH_Latency_2);

        RCC_HCLKConfig(RCC_SYSCLK_Div1);

        RCC_PCLK2Config(RCC_HCLK_Div1);

        RCC_PCLK1Config(RCC_HCLK_Div2);

        RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

        RCC_PLLCmd(ENABLE);

        while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)

        {

        }

        RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);

        while(RCC_GetSYSCLKSource() != 0x08)

        {

        }

        }

        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_GPIOA| RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOB

        | RCC_APB2Periph_AFIO, ENABLE);

        }

        void GPIO_Configuration(void)

        {

        GPIO_InitTypeDef GPIO_InitStructure;

        GPIO_InitStructure.GPIO_Pin =GPIO_Pin_All;

        GPIO_InitStructure.GPIO_Speed =GPIO_Speed_50MHz;

        GPIO_InitStructure.GPIO_Mode =GPIO_Mode_Out_PP;

        GPIO_Init(GPIOB, GPIO_InitStructure);

        }

        void NVIC_Configuration(void)

        {

        //NVIC_InitTypeDef NVIC_InitStructure;

        #ifdef VECT_TAB_RAM

        NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

        #else

        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

        #endif

        }



        關鍵詞: 程序 STM32

        評論


        相關推薦

        技術專區

        關閉
        主站蜘蛛池模板: 石渠县| 高密市| 镇坪县| 长泰县| 海门市| 福清市| 祥云县| 博兴县| 曲水县| 平乡县| 苍梧县| 于田县| 桃园县| 乌兰浩特市| 临沧市| 凌源市| 额尔古纳市| 阜阳市| 福建省| 扎兰屯市| 溆浦县| 永泰县| 新绛县| 井研县| 临沭县| 伊金霍洛旗| 锦州市| 邛崃市| 曲阜市| 正蓝旗| 金阳县| 灵寿县| 万源市| 武清区| 霞浦县| 隆子县| 化隆| 花莲市| 平泉县| 梅河口市| 鄢陵县|