STM32F4 Discovery STM32F4 Discovery Dokunmatik Ekrana Resim Çizme Uygulaması By Konuk Yazar Posted on 7 Şubat 2015 15 min read 2 0 3,399 Paylaş ! Facebook Paylaş ! Twitter Paylaş ! Google+ Paylaş ! Reddit Paylaş ! Pinterest Paylaş ! Linkedin Paylaş ! Tumblr Merhaba arkadaşlar yeni ve özgün bir uygulamayla tekrar karşınızdayız.Bu yazımızda bizden çok kodlar konuşacağı için çok fazla açıklama yapmak istemiyorum.Aşağıda paylaşacağım kodları derleyerek daha güzel projeler elde edeceğinizi düşünüyoruz.Bu uygulama temel olarak dokunmatik ekrana resim nasıl çizilirden çok daha fazla bilgi içermektedir.Tabi ki bunun için kodları dikkatle incelemenizi tavsiye ediyorum.Özellikle yazı nasıl yazdırılır,buton nasıl çizdirilir vb. detayları göreceğinizi umuyorum. [php] #include "stm32f4xx.h" #include "string.h" #include "stdint.h" #include "stdlib.h" #include "stdio.h" #include "delay.h" #include "SSD1289.h" #include "touch_7846.h" #include "fonts.h" #include "stm32f4xx_it.h" #include "stm32f4xx_gpio.h" #include "stm32f4_discovery.c" #define ADC3_DR_ADDRESS ((uint32_t)0x4001224C) #include "timeCalculate.h" // #define DEMCR_TRCENA 0x01000000 uint32_t m_nStart,m_nStart1; //DEBUG Stopwatch start cycle counter value uint32_t m_nStop,m_nStop1; //DEBUG Stopwatch stop cycle counter value // /* Core Debug registers */ // #define DEMCR (*((volatile uint32_t *)0xE000EDFC)) // #define DWT_CTRL (*(volatile uint32_t *)0xe0001000) // #define CYCCNTENA (1<<0) // #define DWT_CYCCNT ((volatile uint32_t *)0xE0001004) // #define CPU_CYCLES *DWT_CYCCNT // #define STOPWATCH_START { m_nStart = *((volatile unsigned int *)0xE0001004);}//DWT_CYCCNT;} // #define STOPWATCH_STOP { m_nStop = *((volatile unsigned int *)0xE0001004);} // #include "Julija.h" TIM_ICInitTypeDef TIM_ICInitStructure; GPIO_InitTypeDef GPIO_InitStructure; int x; extern unsigned char flag; char buffer[40]; float ubuffer[40]; char bufferx[40]; u32 timer3Value; u32 timer3IRQvalue; u32 frequencyH; u32 frequencyL; u32 frequencyK; u32 frequencyC; u32 total=0; u32 cycles0=0; u32 cycles1=0; u32 cycles2=0; u32 freqc_high=0; u32 freqc_low=0; uint16_t i; uint16_t Xpos; uint16_t Ypos; uint16_t a; uint16_t Width; uint16_t Height; uint16_t Length; uint8_t Direction; char stringas[8]; int xold,yold; void LCD(unsigned char *text); void frequencyCalculate(void); void smc_drawButton(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height); void TIM2_IRQHandler(void) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); GPIO_ToggleBits(GPIOD,GPIO_Pin_12); GPIOD->ODR ^= 0x0000008000; frequencyCalculate(); if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { // TIM_ClearITPendingBit(TIM2, TIM_IT_Update); } } void TIM3_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure3; /* GPIOC clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); /* TIM3 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); /* GPIOA Configuration: TIM3 CH1 (PC6) */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation GPIO_Init(GPIOC, &GPIO_InitStructure); /* Connect TIM3 pins to AF */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_TIM3); TIM_TimeBaseStructure3.TIM_Period = 65535; TIM_TimeBaseStructure3.TIM_Prescaler = 0; TIM_TimeBaseStructure3.TIM_ClockDivision = 0; TIM_TimeBaseStructure3.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure3); TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising,0); //TIM_Cmd(TIM3, ENABLE); } /** * @brief Setup an interval timer * @param None * @retval None */ void INTTIM_Config(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure2; NVIC_InitTypeDef NVIC_InitStructure; /* Enable the TIM2 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* TIM2 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); /* Time base configuration */ TIM_TimeBaseStructure2.TIM_Period = 1000000 – 1; // 1 MHz down to 1 KHz (1 ms) TIM_TimeBaseStructure2.TIM_Prescaler = 84-1; // 24 MHz Clock down to 1 MHz (adjust per your clock) TIM_TimeBaseStructure2.TIM_ClockDivision = 0; TIM_TimeBaseStructure2.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure2); /* TIM IT enable */ TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); } void LCD_DrawButton1(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height,int position) { // dikdörtgen ciz LCD_SetTextColor(DGRAY); LCD_DrawFullRect( Xpos, Ypos,Width,Height); // dikdörtgenin üst ve sol kenarina cizgi ciz // LCD_SetBackColor(LGRAY); if(position==0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(BLACK); LCD_DrawLine( Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); LCD_DrawLine( Xpos, Ypos, Height, LCD_DIR_VERTICAL); if(position!=0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(BLACK); } void LCD_DrawButton(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height,int position) { // dikdörtgen ciz LCD_SetTextColor(DGRAY); LCD_DrawFullRect( Xpos, Ypos,Width,Height); // dikdörtgenin üst ve sol kenarina cizgi ciz if(position==0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(BLACK); LCD_DrawLine( Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); LCD_DrawLine( Xpos, Ypos, Height, LCD_DIR_VERTICAL); if(position!=0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(BLACK); } void LCD_DrawButton2(uint16_t Xpos, uint16_t Ypos, uint16_t Width, uint16_t Height,int position) { // dikdörtgen ciz LCD_SetTextColor(DGRAY); LCD_DrawFullRect( Xpos, Ypos,Width,Height); // dikdörtgenin üst ve sol kenarina cizgi ciz if(position==0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(BLACK); LCD_DrawLine( Xpos, Ypos, Width, LCD_DIR_HORIZONTAL); LCD_DrawLine( Xpos, Ypos, Height, LCD_DIR_VERTICAL); if(position!=0) LCD_SetTextColor(WHITE); else LCD_SetTextColor(GREEN); } void binary(int deger) { if(!deger) return; printf("%d",deger%2); deger = deger/2; binary(deger); return; } void frequencyCalculate(void) { total=TIM3->CNT; TIM_Cmd(TIM3, DISABLE); TIM_Cmd(TIM2, DISABLE); // TIM3->SR=0; // TIM2->SR=0; // sprintf(buffer,"%04hd %06hd %04hd",frequencyH,timer3Value,timer3IRQvalue); total=((frequencyH*65536)+total); sprintf(buffer,"%012Lu",total); LCD_StringLine2(10, 200, buffer); // sprintf(buffer,"%06Lu %06Lu %04Lu %06Lu",frequencyH,timer3Value,timer3IRQvalue,TIM3->CNT); // LCD_StringLine2(10, 100, buffer); TIM3->SR=0; timer3Value=0; timer3IRQvalue=0; frequencyH=0; TIM3->CNT=0; TIM_Cmd(TIM3, ENABLE); TIM_Cmd(TIM2, ENABLE); } /////////////////////////////////////// GPIO_InitTypeDef GPIO_Init_Struct; void init_gpio(void) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE); GPIO_Init_Struct.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13; GPIO_Init_Struct.GPIO_Mode = GPIO_Mode_OUT; GPIO_Init_Struct.GPIO_OType= GPIO_OType_PP; GPIO_Init_Struct.GPIO_Speed= GPIO_Speed_100MHz; GPIO_Init_Struct.GPIO_PuPd=GPIO_PuPd_NOPULL; GPIO_Init(GPIOD,&GPIO_Init_Struct); } u16 timEnCycle =0; u16 timDisCycle =0; u32 get_freq(uint32_t ticks) { // int m=0; cycles0=0; cycles1=0; cycles2=0; freqc_high=0; TIM3->CNT=0; // cycles0 > 5953400 /*_ wait one second___ */ ticks += timEnCycle; stopwatch_reset(); TIM_Cmd(TIM3, ENABLE); while(CPU_CYCLES < ticks) { if(TIM3->SR&TIM_SR_UIF) { //TIM3->SR=0; TIM3->SR &= ~TIM_SR_UIF; freqc_high++; } cycles2++; } TIM_Cmd(TIM3, DISABLE); STOPWATCH_STOP2; m_nStop1 = m_nStop1-(timDisCycle+timEnCycle); /*_ 1 saniye sonunda bekle___ */ if(TIM3->SR&TIM_SR_UIF) { frequencyH++; } freqc_low=TIM3->CNT; total=((freqc_high*65536)+freqc_low); return total; } int main(void) { int ma=0; int timeDiff = 0; u32 okumahizi=0; u16 cizildimi = 0; u16 cizildimi1 = 0; init_gpio(); LCD_Clear(WHITE); LCD_Init(); touch_init(); //Touch_Adjust(); Pixel(Pen_Point.X0,Pen_Point.Y0,WHITE); Pixel(Pen_Point.X0,Pen_Point.Y0+1,WHITE); Pixel(Pen_Point.X0+1,Pen_Point.Y0,WHITE); Pixel(Pen_Point.X0+1,Pen_Point.Y0+1,WHITE); LCD_Clear(GREEN); // xpos=30; // ypos=30; i=0; timer3Value=0; timer3IRQvalue=0; frequencyH=0; /* TIM2 disable counter */ TIM_Cmd(TIM2, DISABLE); stopwatch_reset(); TIM_Cmd(TIM3, ENABLE); STOPWATCH_STOP; timEnCycle =m_nStop; stopwatch_reset(); TIM_Cmd(TIM3, DISABLE); STOPWATCH_STOP; timDisCycle =m_nStop; // INTTIM_Config(); TIM3_Configuration(); TIM_Cmd(TIM3, DISABLE); TIM3->CNT=0; okumahizi = SystemCoreClock/1000; LCD_SetTextColor(DGRAY); LCD_StringLine(50, 130, "www.roboturka.com"); LCD_SetTextColor(DGRAY); LCD_StringLine(80, 110, "BILAL KAYA"); stopwatch_reset(); while(1) { frequencyK= get_freq(okumahizi); timeDiff = CalcNanosecondsFromStopwatch2(m_nStart1, m_nStop1); ma++; Convert_Pos(); LCD_CharSize(16); LCD_SetTextColor(BLUE); LCD_StringLine(50, 296, "Temizle"); if((short int)Pen_Point.X0>0 && (short int)Pen_Point.X0<30&& (short int)Pen_Point.Y0>280 && (short int)Pen_Point.Y0<310) { if(cizildimi==1) { cizildimi=0; } } else { if(cizildimi==0) { cizildimi=1; } } if((short int)Pen_Point.X0>50&& (short int)Pen_Point.X0<100&& (short int)Pen_Point.Y0>280 && (short int)Pen_Point.Y0<320) { if(cizildimi1==1) { LCD_SetTextColor(MAROON); LCD_Clear(WHITE); } } else { if(cizildimi1==0) { cizildimi1=1; } } if((short int)Pen_Point.X0>0 && (short int)Pen_Point.Y0>0) { LCD_DrawFullCircle(Pen_Point.X0,Pen_Point.Y0,2); } } } [/php] Program dosyalarına buradan ulaşabilirsiniz…