- #define _ST7735_C_
- #include "platform.h"
- #include "st7735.h"
- #include "charcode.h"
- #define LCD_CS_SET() SPI_CSInternalSelected(SPI2, DISABLE)
- #define LCD_CS_RESET() SPI_CSInternalSelected(SPI2, ENABLE)
- #define LCD_DC GPIOB,GPIO_Pin_10 //
- #define LCD_RST GPIOB,GPIO_Pin_11 //
- #define LCD_LED GPIOB,GPIO_Pin_1 //
- #define LCD_DC_SET() GPIO_WriteBit(LCD_DC, Bit_SET);
- #define LCD_DC_RESET() GPIO_WriteBit(LCD_DC, Bit_RESET);
- #define LCD_RST_SET() GPIO_WriteBit(LCD_RST, Bit_SET);
- #define LCD_RST_RESET() GPIO_WriteBit(LCD_RST, Bit_RESET);
- #define LCD_LED_SET() GPIO_WriteBit(LCD_LED, Bit_SET);
- #define LCD_LED_RESET() GPIO_WriteBit(LCD_LED, Bit_RESET);
- extern void SPI_FLASH_FastRead(uint32_t Address, uint8_t *Buffer, uint32_t Length);
- uint8_t MatrixBuff[32];
- void getMatrix(const uint16_t nmCode)
- {
- uint8_t i;
- uint32_t offset;
- uint8_t GBH,GBL;
- uint16_t nm=nmCode;
- GBH=nm>>8&0xff;
- GBL=nm&0xff;
- if(GBH>=0xb0)
- {
- offset=((GBH-0xa7)*94+GBL-0xa1)*32;
- }else
- {
- offset=((GBH-0xa1)*94+GBL-0xa1)*32;
- }
-
- SPI_FLASH_FastRead(offset,MatrixBuff,32);
-
- }
- typedef struct {
- uint8_t cmd;
- uint8_t dat[16];
- uint16_t datLen;
- uint32_t sleep;
- } st7735_ini_str_t;
- st7735_ini_str_t lcd_ini_str[] = {
- {0x11, {0x00}, 0, 120}, /* software reset */
- {0xB1, {0x02, 0x35, 0x36}, 3, 0},
- {0xB2, {0x02,0x35,0x36}, 3 ,0}, //Frame rate 80Hz
- {0xB3, {0x02,0x35,0x36,0x02,0x35,0x36}, 6 ,0},
- {0xB4, {0x03}, 1, 0 },
- {0xC0, {0xA2,0x02,0x84}, 3 ,0},
- {0xC1, {0xC5}, 1 ,0},
- {0xC2, {0x0D,0x00}, 2,0},
- {0xC3, {0x8D,0x2A}, 2,0},
- {0xC4, {0x8D,0xEE}, 2,0},
- {0xC5, {0x0A}, 1,0},
- {0xC7, {0x00},1,0},
- {0x36, {0xC8}, 1,0},
- {0xE0, {0x12,0x1C,0x10,0x18,0x33,0x2C,0x25,0x28,0x28,0x27,0x2F,0x3c,0x00,0x03,0x03,0x10}, 16,0},
- {0xE1, {0x12,0x1C,0x10,0x18,0x2D,0x28,0x23,0x28,0x28,0x26,0x2F,0x3B,0x00,0x03,0x03,0x10}, 16,0},
- {0x3A, {0x05}, 1, 0}, //65k mode
- {0x29, {0x00}, 0, 0}, //Display on
- {0x00, {0x00}, 0, 0} /* EOL */
- };
- void LCD_SPI_Configure(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- SPI_InitTypeDef SPI_InitStruct;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
-
- SPI_StructInit(&SPI_InitStruct);
- SPI_InitStruct.SPI_Mode = SPI_Mode_Master;
- SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStruct.SPI_DataWidth = 8;
- SPI_InitStruct.SPI_CPOL = SPI_CPOL_Low;
- SPI_InitStruct.SPI_CPHA = SPI_CPHA_1Edge;
- SPI_InitStruct.SPI_NSS = SPI_NSS_Soft;
- SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
- SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;
- SPI_Init(SPI2, &SPI_InitStruct);
-
- SPI_BiDirectionalLineConfig(SPI2, SPI_Direction_Rx);
- SPI_BiDirectionalLineConfig(SPI2, SPI_Direction_Tx);
-
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
-
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource12, GPIO_AF_5); //SPI2_NSS PB12
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_5); //SPI2_SCK PB13
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_5); //SPI2_MISO PB14
- GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_5); //SPI2_MOSI PB15
-
-
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_15;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_14;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- SPI_Cmd(SPI2, ENABLE);
-
-
- //初始化LCD_DC、LCD_RST、LCD_LED
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_10|GPIO_Pin_11;
- GPIO_InitStruct.GPIO_Speed = GPIO_Speed_High;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
-
- }
- /***********************************************************************************************************************
- * @brief
- * [url=home.php?mod=space&uid=536309]@NOTE[/url] none
- * @param none
- * @retval none
- *********************************************************************************************************************/
- void LCD_SPI_TxData_Polling(uint8_t *Buffer, uint8_t Length)
- {
- uint8_t i = 0, Data = 0;
- for (i = 0; i < Length; i++)
- {
- //SPI_SendData(SPI2, Buffer[i]);
- SPI_SendByte(SPI2, Buffer[i]);
- while (RESET == SPI_GetFlagStatus(SPI2, SPI_FLAG_TXEPT))
- {
- }
- while (RESET == SPI_GetFlagStatus(SPI2, SPI_FLAG_RXAVL))
- {
- }
- Data = SPI_ReceiveData(SPI2);
- }
- }
- /*写指令*/
- void LCD_WriteIndex(uint8_t index)
- {
- LCD_CS_RESET();
- LCD_DC_RESET();
- LCD_SPI_TxData_Polling(&index,1);
- LCD_CS_SET();
- }
- /*写数据*/
- void LCD_WriteData(uint8_t *Buffer, uint8_t Length)
- {
- LCD_CS_RESET();
- LCD_DC_SET();
- LCD_SPI_TxData_Polling(Buffer,Length);
- LCD_CS_SET();
- }
- void ST7735_SendData(uint8_t cmd, uint8_t *data, uint16_t length)
- {
- LCD_WriteIndex(cmd);
- LCD_WriteData(data,length);
- }
- void ST7735_HardReset()
- {
- LCD_RST_SET();
- PLATFORM_DelayMS(100);
- LCD_RST_RESET();
- PLATFORM_DelayMS(100);
- LCD_RST_SET();
- PLATFORM_DelayMS(100);
- }
- /*发送初始化字符串*/
- void ST7735_SendInitStr()
- {
- LCD_CS_RESET();
- uint16_t i = 0;
- while(lcd_ini_str[i].cmd != 0x00)
- {
- uint8_t cmd = lcd_ini_str[i].cmd;
- uint16_t datLen = lcd_ini_str[i].datLen;
- uint8_t *dat;
- dat = &(lcd_ini_str[i].dat[0]);
- uint32_t slp = lcd_ini_str[i].sleep;
- LCD_DC_RESET();
- LCD_SPI_TxData_Polling(&cmd, 1);
- if(datLen > 0)
- {
- LCD_DC_SET();
- LCD_SPI_TxData_Polling(dat, datLen);
- }
- if(slp > 0)
- {
- PLATFORM_DelayMS(slp);
- }
- i++;
- }
- LCD_CS_SET();
- }
- void ST7735_SetWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
- {
- /* CASET */
- uint8_t cmd = 0x2A;
- x=x+2;
- y=y+2;
- uint8_t buf4[4];
- buf4[0] = (x >> 8) & 0xFF;
- buf4[1] = x & 0xFF;
- buf4[2] = ((x + w -1) >> 8) & 0xFF;
- buf4[3] = (x + w -1) & 0xFF;
- ST7735_SendData(cmd, buf4, 4);
- /* RASET */
- cmd = 0x2B;
- buf4[0] = (y >> 8) & 0xFF;
- buf4[1] = y & 0xFF;
- buf4[2] = ((y + h - 1) >> 8) & 0xFF;
- buf4[3] = (y + h - 1) & 0xFF;
- ST7735_SendData(cmd, buf4, 4);
-
- LCD_WriteIndex(0x2C);
- }
- void Lcd_SetXY(unsigned int x,unsigned int y)
- {
- ST7735_SetWindow(x,y,x,y);
- }
- void setPixel(uint16_t Color)
- {
-
- uint8_t color_h,color_l;
- color_h=Color>>8;
- color_l=Color&0xff;
-
- LCD_CS_RESET();
- LCD_DC_SET();
- LCD_SPI_TxData_Polling(&color_h,1);
- LCD_SPI_TxData_Polling(&color_l,1);
- LCD_CS_SET();
- }
- void LCD_DrawPoint(uint16_t x,uint16_t y,uint16_t Data)
- {
- ST7735_SetWindow(x,y,x+1,y+1);
- //LCD_WriteData((uint8_t*)&Data, 2);
- setPixel(Data);
- }
- //画线函数,使用Bresenham 画线算法
- void Gui_DrawLine(unsigned int x0, unsigned int y0,unsigned int x1, unsigned int y1,unsigned int Color)
- {
- int dx, // difference in x's
- dy, // difference in y's
- dx2, // dx,dy * 2
- dy2,
- x_inc, // amount in pixel space to move during drawing
- y_inc, // amount in pixel space to move during drawing
- error, // the discriminant i.e. error i.e. decision variable
- index; // used for looping
- Lcd_SetXY(x0,y0);
- dx = x1-x0;//计算x距离
- dy = y1-y0;//计算y距离
- if (dx>=0)
- {
- x_inc = 1;
- }
- else
- {
- x_inc = -1;
- dx = -dx;
- }
-
- if (dy>=0)
- {
- y_inc = 1;
- }
- else
- {
- y_inc = -1;
- dy = -dy;
- }
- dx2 = dx << 1;
- dy2 = dy << 1;
- if (dx > dy)//x距离大于y距离,那么每个x轴上只有一个点,每个y轴上有若干个点
- {//且线的点数等于x距离,以x轴递增画点
- // initialize error term
- error = dy2 - dx;
- // draw the line
- for (index=0; index <= dx; index++)//要画的点数不会超过x距离
- {
- //画点
- LCD_DrawPoint(x0,y0,Color);
-
- // test if error has overflowed
- if (error >= 0) //是否需要增加y坐标值
- {
- error-=dx2;
- // move to next line
- y0+=y_inc;//增加y坐标值
- } // end if error overflowed
- // adjust the error term
- error+=dy2;
- // move to the next pixel
- x0+=x_inc;//x坐标值每次画点后都递增1
- } // end for
- } // end if |slope| <= 1
- else//y轴大于x轴,则每个y轴上只有一个点,x轴若干个点
- {//以y轴为递增画点
- // initialize error term
- error = dx2 - dy;
- // draw the line
- for (index=0; index <= dy; index++)
- {
- // set the pixel
- LCD_DrawPoint(x0,y0,Color);
- // test if error overflowed
- if (error >= 0)
- {
- error-=dy2;
- // move to next line
- x0+=x_inc;
- } // end if error overflowed
- // adjust the error term
- error+=dx2;
- // move to the next pixel
- y0+=y_inc;
- } // end for
- } // end else |slope| > 1
- }
- void Gui_DrawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h,uint16_t bc)
- {
- uint16_t i,j;
- ST7735_SetWindow(x, y, w, h);
- for(i=0;i<w;i++)
- {
- for(j=0;j<h;j++)
- {
- setPixel(bc);
- }
- }
- }
- void GUI_Clear(uint16_t Color) //清屏
- {
- uint16_t i,j;
-
- ST7735_SetWindow(0, 0, X_MAX_PIXEL, Y_MAX_PIXEL);
-
- for(i=0;i<Y_MAX_PIXEL;i++)
- {
- for(j=0;j<X_MAX_PIXEL;j++)
- {
- setPixel(Color);
- }
- }
- }
- void GUI_WriteASCII8x16(uint16_t x, uint16_t y, uint8_t *p, uint16_t wordColor, uint16_t backColor)
- {
- unsigned char j, wordByte,wordNum;
- uint16_t mx,my;
- uint8_t color;
-
- mx=x;
- my=y;
-
- while(*p != '\0')
- {
- if(mx>127){
- mx=x;
- my+=16;
- }
- wordNum = *p - 32;
- ST7735_SetWindow(mx,my,8, 16);
-
- for (wordByte=0; wordByte<16; wordByte++)
- {
- color = Font_Data[wordNum].dat[wordByte];
- for (j=0; j<8; j++)
- {
- if ((color&0x80) == 0x80)
- {
- setPixel(wordColor);
- }
- else
- {
- setPixel(backColor);
- }
- color <<= 1;
- }
- }
- p++;
- mx +=8;
- }
- }
- void GUI_WriteCN16x16(uint16_t x, uint16_t y,const uint8_t *cn, uint16_t wordColor, uint16_t backColor)
- {
- uint16_t i, j, mx,my,wordByte;
- uint16_t zm;
- uint16_t color;
- uint8_t wordNum;
- mx=x;
- my=y;
- while (*cn != '\0')
- {
-
- if(mx>119){
- mx=x;
- my+=16;
- }
- if(*cn<128){
- wordNum = *cn - 32;
- ST7735_SetWindow(mx,my,8, 16);
-
- for (wordByte=0; wordByte<16; wordByte++)
- {
- color = Font_Data[wordNum].dat[wordByte];
- for (j=0; j<8; j++)
- {
- if ((color&0x80) == 0x80)
- {
- setPixel(wordColor);
- }
- else
- {
- setPixel(backColor);
- }
- color <<= 1;
- }
- }
- cn++;
- mx +=8;
- }
- else
- {
- ST7735_SetWindow(mx, my, 16, 16);
- zm=*cn;
- zm<<=8;
- zm|=*(cn+1);
- getMatrix(zm);
- for(i=0; i<32; i++)
- { //MSK的位数
- color=MatrixBuff[i];
- for(j=0;j<8;j++)
- {
- if((color&0x80)==0x80)
- {
- setPixel(wordColor);
- }
- else
- {
- setPixel(backColor);
- }
- color<<=1;
- }//for(j=0;j<8;j++)结束
- }
- cn += 2;
- mx += 16;
- }
- }
- }
- void ST7735_Init(void)
- {
- LCD_LED_SET();
- LCD_SPI_Configure();
- ST7735_HardReset();
- ST7735_SendInitStr();
- }
其中,读取字库函数getMatrix,
1、之前将字库写到了外部flash的地址0
2、字库的偏移量计算:因为字库本身去掉了一些不常用的字,所有需要跳过部分地址对GBH>=0xb0进行特殊判断。
- void getMatrix(const uint16_t nmCode)
- {
- uint8_t i;
- uint32_t offset;
- uint8_t GBH,GBL;
- uint16_t nm=nmCode;
- GBH=nm>>8&0xff;
- GBL=nm&0xff;
- if(GBH>=0xb0)
- {
- offset=((GBH-0xa7)*94+GBL-0xa1)*32;
- }else
- {
- offset=((GBH-0xa1)*94+GBL-0xa1)*32;
- }
-
- SPI_FLASH_FastRead(offset,MatrixBuff,32);
-
- }
控制文本显示
gui_text.c
1、article是要显示文本全文。
2、textBuff是一屏可以显示的文本。
- #define _GUI_TEXT_C_
- #include <stdio.h>
- #include <string.h>
- #include "st7735.h"
- #include "gui_text.h"
- #define HZNUM 64
- #define TEXTSIZE HZNUM*2
- uint8_t textBuff[TEXTSIZE];
- const uint8_t article[]="天尊地卑,乾坤定矣。卑高以陈,贵贱位矣。动静有常,刚柔断矣。方以类聚,物以群分,吉凶生矣。在天成象,在地成形,变化见矣。乾知大始,坤作成物。乾以易知,坤以简能。易则易知,简则易从。易知则有亲,易从则有功。有亲则可久,有功则可大。可久则贤人之德,可大则贤人之业。易简,而天下矣之理矣;天下之理得,而成位乎其中矣。第二章圣人设卦观象,系辞焉而明吉凶,刚柔相推而生变化。是故,君子所居而安者,易之序也。所乐而玩者,爻之辞也。是故,君子居则观其象,而玩其辞;动则观其变,而玩其占。是故自**之,吉无不利。第三章彖者,言乎象也。爻者,言乎变者也。吉凶者,言乎其失得也。悔吝者,言乎其疵也。无咎者,善补过也。是故,列贵贱者,存乎位。齐大者,存乎卦。辩吉凶者,存乎辞。忧悔吝者,存乎介。震无咎者,存乎悔。是故,卦有大,辞有险易。辞也者,也各指其所之。第四章易与天地准,故能弥纶天地之道。仰以观於天文,俯以察於地理,是故知幽明之故。原始反终,故知死生之。精气为物,游魂为变,是故知鬼神之情状。与天地相似,故不违。知周乎万物,而道济天下,故不过。旁行而不流,乐天知命,故不忧。安土敦乎仁,故能爱。范围天地之化而不过,曲成万物而不遗,通乎昼夜之道而知,故神无方而易无体。";
- uint16_t curPage=0;
- uint16_t maxPage=sizeof(article)/TEXTSIZE+1;
- void gui_DrawScroll(uint8_t pos)
- {
- Gui_DrawRect(GUI_TEXT_WIDTH+10,0,2,GUI_TEXT_HEIGHT,COLOR_Blue);
- Gui_DrawRect(GUI_TEXT_WIDTH+5,pos,10,pos+20,COLOR_Blue);
- }
- void gui_DrawWindow(void)
- {
- Gui_DrawRect(0,0,GUI_TEXT_WIDTH,GUI_TEXT_HEIGHT,COLOR_DarkGreen);
- gui_DrawScroll(10);
- }
- void gui_SetPage(uint16_t page)
- {
- strncpy((char*)textBuff,(char*)(article+page*TEXTSIZE),TEXTSIZE);
- }
- void gui_DrawWindowText(void)
- {
- gui_SetPage(curPage);
- GUI_WriteCN16x16(0,0,textBuff,COLOR_Yellow,COLOR_Black);
- }
- void gui_textDemo(void)
- {
- GUI_Clear(COLOR_Black);
- gui_DrawWindowText();
- }
KEY控制
exit_interrupt.c
- void EXTI_Configure(void)
- {
- EXTI_InitTypeDef EXTI_InitStruct;
- GPIO_InitTypeDef GPIO_InitStruct;
- NVIC_InitTypeDef NVIC_InitStruct;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- /* K1->PC4->EXTI_Line4 */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_4;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
- GPIO_Init(GPIOC, &GPIO_InitStruct);
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource4);
- EXTI_StructInit(&EXTI_InitStruct);
- EXTI_InitStruct.EXTI_Line = EXTI_Line4;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStruct);
- /* K2->PC5->EXTI_Line5 */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOC, &GPIO_InitStruct);
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource5);
- EXTI_StructInit(&EXTI_InitStruct);
- EXTI_InitStruct.EXTI_Line = EXTI_Line5;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStruct);
- /* K3->PB1->EXTI_Line1 */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource1);
- EXTI_StructInit(&EXTI_InitStruct);
- EXTI_InitStruct.EXTI_Line = EXTI_Line1;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStruct);
- /* K4->PB2->EXTI_Line2 */
- GPIO_StructInit(&GPIO_InitStruct);
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOB, &GPIO_InitStruct);
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource2);
- EXTI_StructInit(&EXTI_InitStruct);
- EXTI_InitStruct.EXTI_Line = EXTI_Line2;
- EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStruct.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStruct);
- /* EXTI Interrupt */
- NVIC_InitStruct.NVIC_IRQChannel = EXTI1_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStruct);
- NVIC_InitStruct.NVIC_IRQChannel = EXTI2_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStruct);
- NVIC_InitStruct.NVIC_IRQChannel = EXTI4_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStruct);
- NVIC_InitStruct.NVIC_IRQChannel = EXTI9_5_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStruct);
- }
mm32f5330_it.c
中断方式实现KEY翻页
- void EXTI2_IRQHandler(void)
- {
- /* K4 */
- if (SET == EXTI_GetITStatus(EXTI_Line2))
- {
- PLATFORM_LED_Toggle(LED4);
- if(curPage<maxPage) {
- curPage++;
- gui_DrawWindowText();
- }
- EXTI_ClearITPendingBit(EXTI_Line2);
- }
- }
- void EXTI9_5_IRQHandler(void)
- {
- /* K2 */
- if (SET == EXTI_GetITStatus(EXTI_Line5))
- {
- PLATFORM_LED_Toggle(LED2);
- if(curPage>0) {
- curPage--;
- gui_DrawWindowText();
- }
- EXTI_ClearITPendingBit(EXTI_Line5);
- }
- }
源码:
mini-f53330_USART_Polling.rar
(187.81 KB, 下载次数: 4)