版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、#include "led.h"#include "sys.h"#include "delay.h"#include "adc.h"#include "lcd.h"#include "usart.h"#include "lcdfot.h"#include "hx711.h"#include "key.h"int main(void)u8 num,flag;float vol1;delay_init();uart_in
2、it(9600);LED_Init();LCD_Init();Adc_Init();KEY_Init();HX711_Init();POINT_COLOR=RED;HZ_show();LCD_ShowString(54+25,55,200,24,16,":000.00g");/提示信息顯示LCD_ShowString(54+25,85,200,24,16,":00.00$");/提示信息顯示LCD_ShowString(54+25,115,200,24,16,":000.00$");/提示信息顯示LCD_ShowString(54+2
3、5,145,200,24,16,":000.00g");/提示信息顯示while(1)vol1=HX711_count();if(KEY_Scan(1)=WKUP_PRES) /單價(jià)設(shè)置 num的值可直接用 num+;if(num=100)num=0;LCD_ShowxNum(54+25+8,85,num,2,16,0);if(KEY_Scan(1)=KEY0_PRES) /控制金額是否累加flag=1是累加 flag=0不累加HZ_show_moy();flag+;LED0=0;if(flag=2)LED0=1;LCD_ShowString(54+25+32+30,115
4、,200,16,16," ");flag=0;printf("%d",flag);delay_ms(300);LED1=!LED1;#include "lcd.h"#include "lcdfot.h"u8 table1=0x00,0x00,0x00,0x00,0x00,0x04,0x02,0x00,0x04,0x02,0x00,0x04,0x02,0x00,0x24,0x0A,0xFF,0xA4,0x0A,0x7F,0x24,0x0A,0x49,0x24,0x12,0x49,0x24,0x12,0x49,0x24
5、,0x12,0x49,0x24,0x1F,0xFF,0xFC,0x12,0x49,0x24,0x12,0x49,0x24,0x12,0x49,0x24,0x22,0x49,0x24,0x22,0x49,0x24,0x22,0xFF,0xA4,0x02,0x40,0x64,0x06,0x00,0x24,0x06,0x00,0x0C,0x02,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,;/*重*/u8 table2=0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x02,0x00,0x40,0x02,0x00,0x40,0x1
6、2,0x3F,0xDF,0xD2,0x3F,0x52,0x92,0x25,0x52,0x92,0x25,0x52,0x92,0x25,0x52,0x92,0x25,0x52,0x92,0x25,0x5F,0xFC,0x25,0x5F,0xFC,0x25,0x52,0x92,0x25,0x52,0x92,0x25,0x52,0x92,0x25,0x52,0x92,0x3F,0x5F,0xD2,0x20,0x5F,0xB2,0x00,0x40,0x12,0x00,0x40,0x04,0x00,0xC0,0x04,0x00,0x40,0x00,0x00,0x00,0x00,;/*量*/u8 tabl
7、e3=0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x40,0x00,0x00,0x40,0x03,0xFE,0x40,0x02,0x22,0x40,0x22,0x22,0x40,0x32,0x22,0x40,0x1E,0x22,0x40,0x02,0x22,0x40,0x03,0xFF,0xFE,0x02,0x22,0x40,0x06,0x22,0x40,0x0A,0x22,0x40,0x72,0x22,0x40,0x22,0x22,0x40,0x02,0x22,0x40,0x03,0xFE,0x40,0x02,0x00,0x
8、40,0x00,0x00,0xC0,0x00,0x00,0xC0,0x00,0x00,0x40,0x00,0x00,0x00,;/*單*/u8 table4=0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x10,0x00,0x00,0x60,0x00,0x01,0xC0,0x00,0x07,0xFF,0xFE,0x3C,0x80,0x00,0x30,0x10,0x02,0x00,0x20,0x04,0x00,0x40,0x08,0x00,0x80,0x18,0x03,0x3F,0xE0,0x06,0x3E,0x00,0x3C,0x00,0x00,0x30,0x00,0
9、x00,0x0C,0x00,0x00,0x02,0x00,0x01,0x01,0x3F,0xFE,0x00,0x80,0x00,0x00,0xC0,0x00,0x00,0x60,0x00,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,;/*價(jià)*/u8 table5=0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x00,0x08,0x00,0x01,0x08,0x08,0x01,0x08,0x0C,0x01,0x08,0x1C,0x01,0x08,0x2C,0x01,0x08,0x4C,0x01,0x08,
10、0x88,0x01,0x0B,0x08,0x3F,0xFE,0x08,0x3F,0xF8,0x08,0x01,0x08,0x08,0x01,0x08,0x08,0x01,0x08,0x48,0x01,0x08,0x68,0x01,0x08,0x38,0x03,0x08,0x18,0x01,0x08,0x1E,0x00,0x18,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,;/*去*/u8 table6=0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x04,0x00,0x00,0x18,0x00,0x00
11、,0xE2,0x07,0xFF,0x82,0x02,0x00,0x02,0x02,0x00,0x02,0x02,0x08,0x04,0x02,0x0E,0x04,0x02,0x09,0x08,0x02,0x08,0xC8,0x7F,0xF0,0x70,0x3F,0xF0,0x30,0x02,0x08,0x70,0x02,0x09,0x88,0x02,0x0B,0x0C,0x02,0x0E,0x0C,0x02,0x98,0x04,0x07,0x08,0x06,0x06,0x00,0x06,0x00,0x00,0x04,0x00,0x00,0x04,0x00,0x00,0x00,;/*皮*/u8
12、table7=0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x08,0x02,0x00,0x10,0x02,0x00,0x21,0x02,0x00,0x41,0x82,0x00,0xC1,0x42,0x01,0x91,0x32,0x03,0x11,0x1A,0x0E,0x11,0x02,0x38,0x11,0x02,0x30,0x1F,0xFC,0x28,0x11,0x02,0x04,0x11,0x02,0x02,0x11,0x04,0x01,0x11,0x1A,0x00,0xA1,0xE2,0x00,0xD1,0x42,0x00,0x62,0x02,0x00,0x6
13、2,0x02,0x00,0x30,0x04,0x00,0x20,0x04,0x00,0x20,0x00,0x00,0x00,0x00,;/*金*/u8 table8=0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x08,0x80,0x0C,0x31,0x00,0x04,0xD3,0xFC,0x07,0x96,0x84,0x24,0x5C,0x84,0x1C,0x58,0x84,0x04,0x68,0x84,0x05,0xCD,0xFC,0x06,0x06,0x00,0x0C,0x02,0x02,0x16,0x00,0x02,0x11,0xFF,0x84,0x11,0x
14、00,0x08,0x13,0x00,0x10,0x1D,0x47,0xE0,0x11,0x3F,0x00,0x11,0x20,0x20,0x11,0x00,0x10,0x11,0xFF,0xD8,0x23,0xFF,0x8C,0x00,0x00,0x06,0x00,0x00,0x00,;/*額*/u8 table9=0x00,0x00,0x00,0x01,0x7C,0x12,0x54,0x94,0x54,0x90,0x55,0xB2,0x56,0xB1,0x7C,0xDE,0x54,0xD0,0x54,0x90,0x55,0x14,0x54,0x32,0x7C,0x19,0x00,0x00,0
15、x00,0x00,0x00,0x00,;/*累*/u8 table10=0x08,0x01,0x08,0x02,0x08,0x0C,0xFF,0xF0,0x08,0x02,0x08,0x01,0x0F,0xFE,0x00,0x00,0x00,0x00,0x1F,0xFE,0x10,0x04,0x10,0x04,0x10,0x04,0x1F,0xFE,0x00,0x00,0x00,0x00,;/*加*/ 顯示一個漢字/u8 lcdoneHZ(u8 x,u8 y,unsigned char *code) u8 temp,t,y0,t1;u8 table72;y0=y;POINT_COLOR=RED
16、;for(t=0;t<72;t+)temp= *code+;for(t1=0;t1<8;t1+)if(temp&0x80)LCD_DrawPoint(x,y);temp<<=1;y+;if(y-y0)=24)y=y0;x+;break;u8 lcdone16HZ(u8 x,u8 y,unsigned char *code) u8 temp,t,y0,t1;u8 table32;y0=y;POINT_COLOR=RED;for(t=0;t<32;t+)temp= *code+;for(t1=0;t1<8;t1+)if(temp&0x80)LCD
17、_DrawPoint(x,y);temp<<=1;y+;if(y-y0)=16)y=y0;x+;break;void HZ_show(void)lcdoneHZ(30,50,table1);/重量lcdoneHZ(54,50,table2);lcdoneHZ(30,80,table3); /單價(jià)lcdoneHZ(54,80,table4);lcdoneHZ(30,110,table7); /金額lcdoneHZ(54,110,table8); /金額lcdoneHZ(30,140,table5);/去皮lcdoneHZ(54,140,table6);void HZ_show_moy
18、(void)lcdone16HZ(54+25+32+30,115,table9);lcdone16HZ(54+25+32+30+17,115,table10);#ifndef _LCDFOT_H#define _LCDFOT_H#include "sys.h"u8 lcdoneHZ(u8 x,u8 y,unsigned char *code); /顯示24位漢字 u8 lcdone16HZ(u8 x,u8 y,unsigned char *code); /顯示16位漢字void HZ_show(void);void HZ_show_moy(void);#endif#incl
19、ude "hx711.h"#include "delay.h"#include "usart.h"void HX711_Init(void) GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); /使能PE端口時(shí)鐘 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; /LED0->PB.5 端口配置 GPIO_InitStructure.GPIO_Mode = GPIO_
20、Mode_Out_PP; /推挽輸出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; /IO口速度為50MHz GPIO_Init(GPIOA, &GPIO_InitStructure); /根據(jù)設(shè)定參數(shù)初始化GPIOB.5 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; /LED0->PB.5 端口配置 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; /上拉輸入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_
21、50MHz; /IO口速度為50MHz GPIO_Init(GPIOA, &GPIO_InitStructure); /根據(jù)設(shè)定參數(shù)初始化GPIOB.5 GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6);u32 HX711_read(void)u32 count;u8 i;delay_us(1);HX711_SCL=0;count=0;while(HX711_DOUT);for(i=0;i<24;i+)HX711_SCL=1;count=count<<1;HX711_SCL=0;if(HX711_DOUT)count+;HX711_S
22、CL=1;count=count0x800000;delay_us(1);HX711_SCL=0;return count;/得到的質(zhì)量單位是 g 克float HX711_count(void)u8 a;u32 adc,wei;float vol;for(a=10;a>0;a-)adc=HX711_read();wei=wei+adc;wei=wei/10;printf("hx711值:%drn",wei);vol=(float)(wei-7431260)/1118)-1.8-1.55; /注意改參數(shù)wei=0;printf("重量=%frn",
23、vol);return vol;#ifndef _HX711_H#define _HX711_H #include "sys.h"#define HX711_SCL PAout(5)#define HX711_DOUT PAin(6)void HX711_Init(void);u32 HX711_read(void);float HX711_count(void);#endif#include "lcd.h"#include "stdlib.h"#include "font.h" #include "us
24、art.h" #include "delay.h" / /本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途/2.4/2.8寸/3.5寸 TFT液晶驅(qū)動 /支持驅(qū)動IC型號包括:ILI9341/ILI9325/RM68042/RM68021/ILI9320/ILI9328/LGDP4531/LGDP4535/SPFD5408/SSD1289/1505/B505/C505等 /正點(diǎn)原子ALIENTEK/*/V1.2修改說明/支持了SPFD5408的驅(qū)動,另外把液晶ID直接打印成HEX格式.方便查看LCD驅(qū)動IC./V1.3/加入了快速IO的支持/修改了背光控制的
25、極性(適用于V1.8及以后的開發(fā)板版本)/對于1.8版本之前(不包括1.8)的液晶模塊,請修改LCD_Init函數(shù)的LCD_LED=1;為LCD_LED=1;/V1.4/修改了LCD_ShowChar函數(shù),使用畫點(diǎn)功能畫字符。/加入了橫豎屏顯示的支持/V1.5 20110730/1,修改了B505液晶讀顏色有誤的bug./2,修改了快速IO及橫豎屏的設(shè)置方式./V1.6 20111116/1,加入對LGDP4535液晶的驅(qū)動支持/V1.7 20120713/1,增加LCD_RD_DATA函數(shù)/2,增加對ILI9341的支持/3,增加ILI9325的獨(dú)立驅(qū)動代碼/4,增加LCD_Scan_Dir
26、函數(shù)(慎重使用) /6,另外修改了部分原來的函數(shù),以適應(yīng)9341的操作/V1.8 20120905/1,加入LCD重要參數(shù)設(shè)置結(jié)構(gòu)體lcddev/2,加入LCD_Display_Dir函數(shù),支持在線橫豎屏切換/V1.9 20120911/1,新增RM68042驅(qū)動(ID:6804),但是6804不支持橫屏顯示!原因:改變掃描方式,/導(dǎo)致6804坐標(biāo)設(shè)置失效,試過很多方法都不行,暫時(shí)無解。/V2.0 20120924/在不硬件復(fù)位的情況下,ILI9341的ID讀取會被誤讀成9300,修改LCD_Init,將無法識別/的情況(讀到ID為9300/非法ID),強(qiáng)制指定驅(qū)動IC為ILI9341,執(zhí)行9
27、341的初始化。/V2.1 20120930/修正ILI9325讀顏色的bug。/V2.2 20121007/修正LCD_Scan_Dir的bug。/ /LCD的畫筆顏色和背景色 u16 POINT_COLOR=0x0000;/畫筆顏色u16 BACK_COLOR=0xFFFF; /背景色 /管理LCD重要參數(shù)/默認(rèn)為豎屏_lcd_dev lcddev; /寫寄存器函數(shù)/regval:寄存器值void LCD_WR_REG(u16 regval) LCD->LCD_REG=regval;/寫入要寫的寄存器序號 /寫LCD數(shù)據(jù)/data:要寫入的值void LCD_WR_DATA(u16
28、data) LCD->LCD_RAM=data; /讀LCD數(shù)據(jù)/返回值:讀到的值u16 LCD_RD_DATA(void) return LCD->LCD_RAM; /寫寄存器/LCD_Reg:寄存器地址/LCD_RegValue:要寫入的數(shù)據(jù)void LCD_WriteReg(u8 LCD_Reg, u16 LCD_RegValue)LCD->LCD_REG = LCD_Reg;/寫入要寫的寄存器序號 LCD->LCD_RAM = LCD_RegValue;/寫入數(shù)據(jù) /讀寄存器/LCD_Reg:寄存器地址/返回值:讀到的數(shù)據(jù)u16 LCD_ReadReg(u8 L
29、CD_Reg) LCD_WR_REG(LCD_Reg);/寫入要讀的寄存器序號delay_us(5); return LCD_RD_DATA();/返回讀到的值 /開始寫GRAMvoid LCD_WriteRAM_Prepare(void) LCD->LCD_REG=lcddev.wramcmd; /LCD寫GRAM/RGB_Code:顏色值void LCD_WriteRAM(u16 RGB_Code) LCD->LCD_RAM = RGB_Code;/寫十六位GRAM/從ILI93xx讀出的數(shù)據(jù)為GBR格式,而我們寫入的時(shí)候?yàn)镽GB格式。/通過該函數(shù)轉(zhuǎn)換/c:GBR格式的顏色值/
30、返回值:RGB格式的顏色值u16 LCD_BGR2RGB(u16 c)u16 r,g,b,rgb; b=(c>>0)&0x1f;g=(c>>5)&0x3f;r=(c>>11)&0x1f; rgb=(b<<11)+(g<<5)+(r<<0); return(rgb); /當(dāng)mdk -O1時(shí)間優(yōu)化時(shí)需要設(shè)置/延時(shí)ivoid opt_delay(u8 i)while(i-);/讀取個某點(diǎn)的顏色值 /x,y:坐標(biāo)/返回值:此點(diǎn)的顏色u16 LCD_ReadPoint(u16 x,u16 y) u16 r=0
31、,g=0,b=0;if(x>=lcddev.width|y>=lcddev.height)return 0;/超過了范圍,直接返回 LCD_SetCursor(x,y); if(lcddev.id=0X9341|lcddev.id=0X6804)LCD_WR_REG(0X2E);/9341/6804 發(fā)送讀GRAM指令else LCD_WR_REG(R34); /其他IC發(fā)送讀GRAM指令 if(lcddev.id=0X9320)opt_delay(2);/FOR 9320,延時(shí)2us if(LCD->LCD_RAM)r=0;/dummy Read opt_delay(2);
32、 r=LCD->LCD_RAM; /實(shí)際坐標(biāo)顏色 if(lcddev.id=0X9341)/9341要分2次讀出 opt_delay(2); b=LCD->LCD_RAM; g=r&0XFF;/對于9341,第一次讀取的是RG的值,R在前,G在后,各占8位g<<=8;else if(lcddev.id=0X6804)r=LCD->LCD_RAM;/6804第二次讀取的才是真實(shí)值if(lcddev.id=0X9325|lcddev.id=0X4535|lcddev.id=0X4531|lcddev.id=0X8989|lcddev.id=0XB505)ret
33、urn r;/這幾種IC直接返回顏色值else if(lcddev.id=0X9341)return (r>>11)<<11)|(g>>10)<<5)|(b>>11);/ILI9341需要公式轉(zhuǎn)換一下else return LCD_BGR2RGB(r);/其他IC /LCD開啟顯示void LCD_DisplayOn(void) if(lcddev.id=0X9341|lcddev.id=0X6804)LCD_WR_REG(0X29);/開啟顯示else LCD_WriteReg(R7,0x0173); /開啟顯示 /LCD關(guān)閉顯示v
34、oid LCD_DisplayOff(void) if(lcddev.id=0X9341|lcddev.id=0X6804)LCD_WR_REG(0X28);/關(guān)閉顯示else LCD_WriteReg(R7,0x0);/關(guān)閉顯示 /設(shè)置光標(biāo)位置/Xpos:橫坐標(biāo)/Ypos:縱坐標(biāo)void LCD_SetCursor(u16 Xpos, u16 Ypos) if(lcddev.id=0X9341|lcddev.id=0X6804) LCD_WR_REG(lcddev.setxcmd); LCD_WR_DATA(Xpos>>8); LCD_WR_DATA(Xpos&0XFF)
35、; LCD_WR_REG(lcddev.setycmd); LCD_WR_DATA(Ypos>>8); LCD_WR_DATA(Ypos&0XFF);elseif(lcddev.dir=1)Xpos=lcddev.width-1-Xpos;/橫屏其實(shí)就是調(diào)轉(zhuǎn)x,y坐標(biāo)LCD_WriteReg(lcddev.setxcmd, Xpos);LCD_WriteReg(lcddev.setycmd, Ypos); /設(shè)置LCD的自動掃描方向/注意:其他函數(shù)可能會受到此函數(shù)設(shè)置的影響(尤其是9341/6804這兩個奇葩),/所以,一般設(shè)置為L2R_U2D即可,如果設(shè)置為其他掃描方式,
36、可能導(dǎo)致顯示不正常./dir:07,代表8個方向(具體定義見lcd.h)/9320/9325/9328/4531/4535/1505/b505/8989/5408/9341等IC已經(jīng)實(shí)際測試 void LCD_Scan_Dir(u8 dir)u16 regval=0;u8 dirreg=0;u16 temp; if(lcddev.dir=1&&lcddev.id!=0X6804)/橫屏?xí)r,對6804不改變掃描方向! switch(dir)/方向轉(zhuǎn)換case 0:dir=6;break;case 1:dir=7;break;case 2:dir=4;break;case 3:di
37、r=5;break;case 4:dir=1;break;case 5:dir=0;break;case 6:dir=3;break;case 7:dir=2;break; if(lcddev.id=0x9341|lcddev.id=0X6804)/9341/6804,很特殊switch(dir)case L2R_U2D:/從左到右,從上到下regval|=(0<<7)|(0<<6)|(0<<5); break;case L2R_D2U:/從左到右,從下到上regval|=(1<<7)|(0<<6)|(0<<5); bre
38、ak;case R2L_U2D:/從右到左,從上到下regval|=(0<<7)|(1<<6)|(0<<5); break;case R2L_D2U:/從右到左,從下到上regval|=(1<<7)|(1<<6)|(0<<5); break; case U2D_L2R:/從上到下,從左到右regval|=(0<<7)|(0<<6)|(1<<5); break;case U2D_R2L:/從上到下,從右到左regval|=(0<<7)|(1<<6)|(1<&l
39、t;5); break;case D2U_L2R:/從下到上,從左到右regval|=(1<<7)|(0<<6)|(1<<5); break;case D2U_R2L:/從下到上,從右到左regval|=(1<<7)|(1<<6)|(1<<5); break; dirreg=0X36; regval|=0X08;/BGR if(lcddev.id=0X6804)regval|=0x02;/6804的BIT6和9341的反了 LCD_WriteReg(dirreg,regval); if(regval&0X20)if
40、(lcddev.width<lcddev.height)/交換X,Ytemp=lcddev.width;lcddev.width=lcddev.height;lcddev.height=temp; else if(lcddev.width>lcddev.height)/交換X,Ytemp=lcddev.width;lcddev.width=lcddev.height;lcddev.height=temp; LCD_WR_REG(lcddev.setxcmd); LCD_WR_DATA(0);LCD_WR_DATA(0);LCD_WR_DATA(lcddev.width-1)>
41、>8);LCD_WR_DATA(lcddev.width-1)&0XFF);LCD_WR_REG(lcddev.setycmd); LCD_WR_DATA(0);LCD_WR_DATA(0);LCD_WR_DATA(lcddev.height-1)>>8);LCD_WR_DATA(lcddev.height-1)&0XFF); else switch(dir)case L2R_U2D:/從左到右,從上到下regval|=(1<<5)|(1<<4)|(0<<3); break;case L2R_D2U:/從左到右,從下到上re
42、gval|=(0<<5)|(1<<4)|(0<<3); break;case R2L_U2D:/從右到左,從上到下regval|=(1<<5)|(0<<4)|(0<<3);break;case R2L_D2U:/從右到左,從下到上regval|=(0<<5)|(0<<4)|(0<<3); break; case U2D_L2R:/從上到下,從左到右regval|=(1<<5)|(1<<4)|(1<<3); break;case U2D_R2L:/從上到
43、下,從右到左regval|=(1<<5)|(0<<4)|(1<<3); break;case D2U_L2R:/從下到上,從左到右regval|=(0<<5)|(1<<4)|(1<<3); break;case D2U_R2L:/從下到上,從右到左regval|=(0<<5)|(0<<4)|(1<<3); break; if(lcddev.id=0x8989)/8989 ICdirreg=0X11;regval|=0X6040;/65K else/其他驅(qū)動IC dirreg=0X03;r
44、egval|=1<<12; LCD_WriteReg(dirreg,regval); /畫點(diǎn)/x,y:坐標(biāo)/POINT_COLOR:此點(diǎn)的顏色void LCD_DrawPoint(u16 x,u16 y)LCD_SetCursor(x,y);/設(shè)置光標(biāo)位置 LCD_WriteRAM_Prepare();/開始寫入GRAMLCD->LCD_RAM=POINT_COLOR; /快速畫點(diǎn)/x,y:坐標(biāo)/color:顏色void LCD_Fast_DrawPoint(u16 x,u16 y,u16 color) if(lcddev.id=0X9341|lcddev.id=0X6804
45、) LCD_WR_REG(lcddev.setxcmd); LCD_WR_DATA(x>>8); LCD_WR_DATA(x&0XFF); LCD_WR_REG(lcddev.setycmd); LCD_WR_DATA(y>>8); LCD_WR_DATA(y&0XFF);else if(lcddev.dir=1)x=lcddev.width-1-x;/橫屏其實(shí)就是調(diào)轉(zhuǎn)x,y坐標(biāo)LCD_WriteReg(lcddev.setxcmd,x);LCD_WriteReg(lcddev.setycmd,y); LCD->LCD_REG=lcddev.wra
46、mcmd; LCD->LCD_RAM=color; /設(shè)置LCD顯示方向(6804不支持橫屏顯示)/dir:0,豎屏;1,橫屏void LCD_Display_Dir(u8 dir)if(dir=0)/豎屏lcddev.dir=0;/豎屏lcddev.width=240;lcddev.height=320;if(lcddev.id=0X9341|lcddev.id=0X6804)lcddev.wramcmd=0X2C; lcddev.setxcmd=0X2A;lcddev.setycmd=0X2B; if(lcddev.id=0X6804)lcddev.width=320;lcddev.
47、height=480;else if(lcddev.id=0X8989)lcddev.wramcmd=R34; lcddev.setxcmd=0X4E;lcddev.setycmd=0X4F; elselcddev.wramcmd=R34; lcddev.setxcmd=R32;lcddev.setycmd=R33; else if(lcddev.id!=0X6804)/6804不支持橫屏顯示 lcddev.dir=1;/橫屏lcddev.width=320;lcddev.height=240;if(lcddev.id=0X9341)lcddev.wramcmd=0X2C; lcddev.se
48、txcmd=0X2A;lcddev.setycmd=0X2B; else if(lcddev.id=0X8989)lcddev.wramcmd=R34; lcddev.setxcmd=0X4F;lcddev.setycmd=0X4E; elselcddev.wramcmd=R34; lcddev.setxcmd=R33;lcddev.setycmd=R32; LCD_Scan_Dir(DFT_SCAN_DIR);/默認(rèn)掃描方向 /初始化lcd/該初始化函數(shù)可以初始化各種ILI93XX液晶,但是其他函數(shù)是基于ILI9320的!/在其他型號的驅(qū)動芯片上沒有測試! void LCD_Init(voi
49、d) GPIO_InitTypeDef GPIO_InitStructure;FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; FSMC_NORSRAMTimingInitTypeDef readWriteTiming; FSMC_NORSRAMTimingInitTypeDef writeTiming; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC,ENABLE);/使能FSMC時(shí)鐘RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPI
50、OD|RCC_APB2Periph_GPIOE|RCC_APB2Periph_GPIOG|RCC_APB2Periph_AFIO,ENABLE);/使能PORTB,D,E,G以及AFIO復(fù)用功能時(shí)鐘 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; /PB0 推挽輸出 背光 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; /推挽輸出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure
51、); /PORTD復(fù)用推挽輸出 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_14|GPIO_Pin_15; /PORTD復(fù)用推挽輸出 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; /復(fù)用推挽輸出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure); /PORTE復(fù)用推挽輸出 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15; /PORTD復(fù)用推挽輸出 GPIO_InitStructure.GPI
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 租車協(xié)議合同范本示例
- 真心相待的夫妻保證書
- 簡單隱私保護(hù)合同協(xié)議樣本
- 規(guī)范文本偷錢保證書范例
- 建筑勞務(wù)分包安全管理協(xié)議
- 精確市場調(diào)研制作合同
- 綠化項(xiàng)目招標(biāo)答疑
- 軟件開發(fā)合同協(xié)議范本示例
- 零售店長工作合同
- 補(bǔ)充合同格式范本
- 材料標(biāo)準(zhǔn)目錄
- 腦卒中后吞咽障礙患者進(jìn)食護(hù)理(2023年中華護(hù)理學(xué)會團(tuán)體標(biāo)準(zhǔn))
- 護(hù)士執(zhí)業(yè)注冊申請表 新
- 妊娠期高血壓疾病診治指南(2022版)解讀
- 公章證照使用登記表
- 哈薩克斯坦勞動法中文版
- 環(huán)境科學(xué)統(tǒng)計(jì)與建模方法-南京大學(xué)中國大學(xué)mooc課后章節(jié)答案期末考試題庫2023年
- 安師大環(huán)境土壤學(xué)課件05土壤水
- 壓力管道驗(yàn)收資料表格
- 2023年康復(fù)醫(yī)學(xué)考試重點(diǎn)復(fù)習(xí)資料
- 《憶讀書》教學(xué)課件
評論
0/150
提交評論