01 > ȸҰ

 
작성일 : 16-10-04 11:20
스폿제어기 REV 3.0 회로도및 프로그램 설치 자료
 글쓴이 : 이로직…
조회 : 6,660  
   SPOT_CTRL_1_ban_cycle.hex (97.3K) [54] DATE : 2016-11-01 16:07:32
   Flash_loader (1).zip (9.4M) [18] DATE : 2016-10-04 11:20:37
   Spot_controller_manual_v3_1.pdf (2.3M) [86] DATE : 2016-12-05 11:42:19
   spot_ctrl_rev_3_0.pdf (92.3K) [37] DATE : 2016-10-17 15:35:59
  • Cortex ARM M3 제어기 자료
1. Download Hex File (oled 구현 함수)
2. Flash Loader Program(flash upgrade 프로그램)
3. 수정 내용: 스폿키를 누를때 한번 스폿으로 수정
4. 10/24일 수정 내용 ( 디폴트 2회 스폿) 타임


  • Main 함수
#include <string.h>
#include "includes.h"

#define CHAR_LCD 0

#if CHAR_LCD 
#define  LCD_Write_string(x,y, s) charLCD_Write_string(x,y, s)
#define  LCD_Write(x,y, s) charLCD_Write(x,y, s)
#define  LCD_Clear() charLCD_Clear()

#define ROW1 0x80   //DDRAM address : 0x00 -> 0x80+0x00
#define ROW2 0xC0   //DDRAM address : 0x40 -> 0x80+0x40
#define ROW3 0x94 //DDRAM address : 0x14 -> 0x80+0x14 
#define ROW4 0xD4 //DDRAM address : 0x54 -> 0x80+0x54 

#else


#define  LCD_Write_string(x,y, s) gLCD_Write_string(x,y, s)
#define  LCD_Write(x,y, s) gLCD_Write(x,y, s)
#define  LCD_Clear() gLCD_Clear()

#define ROW1 0x00  
#define ROW2 0x02  
#define ROW3 0x04    
#define ROW4 0x06     


#endif

   
#define RCC_PLL_MCO                     ((u32)(0x04<<24))
#define RCC_PLL_XTPRE                    ((u32)(0x01<<17))

#define RCC_CFGR2_REG                   (*(volatile u32*)(0x4002102C))

#define ADC_PORT  10

   
#define I2C_SPEED                   50000                    
#define I2C1_SSD1306_SLAVE_ADDRESS8 0x78                      // 8 bit slave address (write)
#define I2C_TIMEOUT                 100000



unsigned long ulClockMS = 0;
RCC_ClocksTypeDef g_RCC_ClocksStatus;

extern BUFFER_TBL gps_buff;
extern uint8_t global_display_buffer[(128*64)/8];

Int32U CriticalSecCntr;

void Button_Test(void);
void LED_Test(void);
void Lcd_Test(void);
void buzzer_test(void);
void gps_test(void);
void tenkey_test(void);
void adc_test(void);
void sht11_test(void);

extern int ssd1306_i2c_draw_buffer(I2C_TypeDef *I2Cx, uint8_t slave_address, uint8_t *buffer_pointer);

void * function[][2]=
{
   {(void *)LED_Test, "LED Test         "},
   {(void *)Button_Test,        "Button Test      "},
   {(void *)Lcd_Test, "Lcd test         "},
   {(void *)buzzer_test,        "buzzer_test      "}, 
   {(void *)gps_test,           "gps_test         "}, 
   {(void *)tenkey_test,        "tenkey_test      "}, 
   {(void *)adc_test,           "adc_test         "}, 
   {(void *)sht11_test,         "sht11_test       "}, 
   {0,0}
};


void Clk_Init (void)
{
  // 1. Clocking the controller from internal HSI RC (8 MHz)
 // RCC_HSICmd(ENABLE);
  // wait until the HSI is ready
  while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI);
  // 2. Enable ext. high frequency OSC
  RCC_HSEConfig(RCC_HSE_ON);
  // wait until the HSE is ready
  while(RCC_GetFlagStatus(RCC_FLAG_HSERDY) == RESET);
  // 3. Init PLL
  RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9|RCC_PLL_MCO); //  8Mhz x 9 = 72MHz
  RCC_PLLCmd(ENABLE);
  // wait until the PLL is ready
  while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
  // 4. Set system clock dividers
  RCC_USBCLKConfig(RCC_USBCLKSource_PLLCLK_1Div5);
  RCC_ADCCLKConfig(RCC_PCLK2_Div8);
  RCC_PCLK2Config(RCC_HCLK_Div1);  //1
  RCC_PCLK1Config(RCC_HCLK_Div2);  //2
  RCC_HCLKConfig(RCC_SYSCLK_Div1);

#ifdef EMB_FLASH
  // 5. Init Embedded Flash
  // Zero wait state, if 0 < HCLK 24 MHz
  // One wait state, if 24 MHz < HCLK 56 MHz
  // Two wait states, if 56 MHz < HCLK 72 MHz  d
  // Flash wait state
  FLASH_SetLatency(FLASH_Latency_2);
  // Half cycle access
  FLASH_HalfCycleAccessCmd(FLASH_HalfCycleAccess_Disable); 
  // Prefetch buffer
  FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
#endif // EMB_FLASH
  // 5. Clock system from PLL
  RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
}



extern unsigned char column ;
extern int bUart3Recv;
int spot_timer_value = 0 ;
int adc_delay_timer = 0;

int spot_timer_delay = 0;
unsigned int spot_count_value = 0;
int oled_error = 0;


int key_pressed(void)
{
     int key = 0;
     key = ((GPIO_ReadInputData(GPIOC) >> 8) & 0x001e) | !((GPIO_ReadInputData(GPIOC) >> 4) & 0x0001);     
     return key;
}
//--------------------------------------------------------------------
void main(void)
{
Int16U  adc_value =0;
Int16U  key_value =0;

 int led_blink_count;
 char num=0,prev_num=0;
 char oled_num,prev_oled_num;
 char hex_num;
 
 int multy_spot_value = 2;


  // Init clock system
   ENTR_CRT_SECTION();  // Main IRQ Disable 
   
   Clk_Init();

  // NVIC init
 
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
  
 
  
  LED_GPIO_init();
  
  segment_out_pin_init();  // status segment 
  
  digital_out_pin_init()  ;    // SPOT EN, DIGITAL OUTPUT

  digital_input_pin_init();


 
  init_i2c1_peripheral(I2C2);  // To Do - Move All this into init_i2c1_peripheral()
 
  KeyInit() ;                    // key board initialize     
                                  // Enable timer counting
  Timer1_initalize();
    
  adcPort_Init();             //adc port initialize
  UART_Initialize(UART1, 115200)  ;
  EXT_CRT_SECTION();    
 
 // Init sequence for 128x64 OLED module
  Dly100us((void *)800);  // loop 300
  oled_error = ssd1306_i2c_init(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8);  
  oled_error = ssd1306_i2c_init(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8);  
  //EXT_CRT_SECTION();        // Main IRQ Enable 
  adc_delay_timer = 100;
  Dly100us((void *)300);  // loop 300
 
  Uart_Printf("ssd1306_i2c_draw_buffer...\r\n");
  if(  oled_error != -1){
    ssd1306_clear_display_buffer(global_display_buffer);
    // ssd1306_i2c_draw_buffer(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8, global_display_buffer);
  }
  
  Uart_Printf("===================================================\r\n");
  Uart_Printf("Spot Controller Firmware Test Program by eLogics!!!\r\n");
  Uart_Printf("================================================== \r\n");

  // LCD CLEAR 
  Dly100us((void *)5000);  // loop 300
  if(  oled_error != -1){
     ssd1306_clear_display_buffer(global_display_buffer);
    
     ssd1306_HAN_string_to_buffer(0,0, "스폿제어기", global_display_buffer);
     ssd1306_string_to_buffer    (96,0,   "V3.0", global_display_buffer);  //5X2X8 =80
             
     ssd1306_HAN_string_to_buffer      (0,    2, "스폿타임", global_display_buffer);
     ssd1306_HAN_string_to_buffer      (0,    4, "멀티스폿", global_display_buffer);
     ssd1306_HAN_string_to_buffer      (0,    6, "스폿누적", global_display_buffer); 
             
     ssd1306_char_to_buffer            (64,   2, ':', global_display_buffer);
     ssd1306_char_to_buffer            (64,   4, ':', global_display_buffer);
     ssd1306_char_to_buffer            (64,   6, ':', global_display_buffer);
             
     ssd1306_char_to_buffer            (94,   2, oled_num/10 + '0', global_display_buffer);  //spot 타임
     ssd1306_char_to_buffer            (102,  2, oled_num%10 + '0', global_display_buffer);
                   
     ssd1306_string_to_buffer          (112,  2, "ms", global_display_buffer); 
     
     ssd1306_char_to_buffer            (94,   6, spot_count_value/1000 + '0', global_display_buffer);  //spot 횟수
     ssd1306_char_to_buffer            (102,   6, (spot_count_value/100)%10 + '0', global_display_buffer);  //spot 횟수
     ssd1306_char_to_buffer            (110,   6, (spot_count_value/10)%10 + '0', global_display_buffer);  //spot 횟수
     ssd1306_char_to_buffer            (118,  6, spot_count_value%10 + '0', global_display_buffer);
     
     ssd1306_char_to_buffer            (94,  4, multy_spot_value%10 + '0', global_display_buffer);
     ssd1306_i2c_draw_buffer(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8, global_display_buffer);
  }  
    // main loop 
  while(1)
  {   
  
     // Uart_Printf("Mission sucessfully completed! \r\n");
      if(adc_delay_timer==0){
        adc_value = GetADCChanel(ADC_PORT);  //여기서 adc 됨      
        num = adc_value / 410;
        oled_num = adc_value / 41;
        if(prev_oled_num != oled_num){
          prev_oled_num = oled_num;
          Uart_Printf("oled ms  valule: %d\r\n",oled_num);            
          if(  oled_error != -1){
             ssd1306_HAN_string_to_buffer(0,0, "스폿제어기", global_display_buffer);
             ssd1306_string_to_buffer    (96,0,   "V3.0", global_display_buffer);  //5X2X8 =80
             
             ssd1306_HAN_string_to_buffer      (0,    2, "스폿타임", global_display_buffer);
             ssd1306_HAN_string_to_buffer      (0,    4, "멀티스폿", global_display_buffer);
             ssd1306_HAN_string_to_buffer      (0,    6, "스폿누적", global_display_buffer); 
             
             ssd1306_char_to_buffer            (64,   2, ':', global_display_buffer);
             ssd1306_char_to_buffer            (64,   4, ':', global_display_buffer);
             ssd1306_char_to_buffer            (64,   6, ':', global_display_buffer);
             
             ssd1306_char_to_buffer            (94,   2, oled_num/10 + '0', global_display_buffer);  //spot 타임
             ssd1306_char_to_buffer            (102,  2, oled_num%10 + '0', global_display_buffer);
                   
             ssd1306_string_to_buffer          (112,  2, "ms", global_display_buffer);                    
             
             ssd1306_i2c_draw_buffer(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8, global_display_buffer);
          }
        }
       
        if(num != prev_num){
          segment_num(num);
          prev_num = num;
        }
        adc_delay_timer = 500;
        
      }
      
      key_value = Getkey();//
      
      if(key_value ==0x01 | key_value ==0x02) { // spot key check
        for(int i =0;i<multy_spot_value;i++){
          
          spot_timer_value = oled_num;  // spot timer set 
          while(spot_timer_value!=0 );    //여기서 spot 됨
   
          spot_timer_delay = 30;                         // spot time delay;
          while(spot_timer_delay != 0);
        }  
        
          Uart_Printf("Spot Count  Valule: %d\r\n", spot_count_value++); 
          if(  oled_error != -1){
            ssd1306_char_to_buffer            (94,   6, spot_count_value/1000 + '0', global_display_buffer);  //spot 횟수
            ssd1306_char_to_buffer            (102,   6, (spot_count_value/100)%10 + '0', global_display_buffer);  //spot 횟수
            ssd1306_char_to_buffer            (110,   6, (spot_count_value/10)%10 + '0', global_display_buffer);  //spot 횟수
            ssd1306_char_to_buffer            (118,  6, spot_count_value%10 + '0', global_display_buffer);
            
            ssd1306_i2c_draw_buffer             (I2C2, I2C1_SSD1306_SLAVE_ADDRESS8, global_display_buffer);
          }
          
          led_blink_count = 65000;
          while(1){
          //while(--led_blink_count > 0 ) {
              led_blink();
              if( key_pressed() == 0x00) {
                break;
              }            
          }
      }
      
      else if(key_value == 0x010) {  // multy spot key time check
        if(multy_spot_value == 6) multy_spot_value = 1;
        else multy_spot_value ++ ;
        
        ssd1306_char_to_buffer            (94,  4, multy_spot_value%10 + '0', global_display_buffer);
        ssd1306_i2c_draw_buffer(I2C2, I2C1_SSD1306_SLAVE_ADDRESS8, global_display_buffer);
        Uart_Printf("multy_spot_value: %d\r\n", multy_spot_value); 
      }
      
      led_sw_blink1();
      Dly100us((void *)200);  // loop 300
      
     
  }  // while loop
}



//-----------------------------------------------
void Button_Test(void)
{

  Uart_Printf("Tachyon 2/3 Firmware Button Test    !!!\r\n");
  LCD_Clear();
  LCD_Write_string(0,ROW1,"button Test");
  
}
//-----------------------------------------------
void sht11_test(void)
{
  char temp_msg[30]; 
  unsigned char error, checksum;
  float humi_sensor,temp_sensor;
  unsigned char humi_value[2], temp_value[2];

  Uart_Printf("Tachyon 2/3 Firmware Temperature_Humi Test    !!!\r\n");
  LCD_Clear();
  Dly100us((void *)100);
  LCD_Write_string(0,ROW1, "Temp_Humi Test:");
  
  while(1){
    Dly100us((void *)10000);
    
    error = 0;

    error += snsSTH11_measure((unsigned char*)&humi_value, &checksum, SNS_HUMI);  // measure humidity
    error += snsSTH11_measure((unsigned char*)&temp_value, &checksum, SNS_TEMP);  // measure temperature

    if (error != 0) 
    {
        snsSTH11_connectionReset();                                        //in case of an error: connection reset
        Uart_Printf("snsSTH11_connectionReset: error: %d\r\n", error);
    }
    else
    { 
       humi_sensor   =(float)( (humi_value[0] << 8) | (humi_value[1]));
       temp_sensor  = (float)( (temp_value[0] << 8) | (temp_value[1]));

       calculate_sth11(&humi_sensor,&temp_sensor);
       
       Uart_Printf("temp:%5.1fC humi:%5.1f%% \n",temp_sensor,humi_sensor);
       sprintf(temp_msg,"T %4.1fC,H %4.1f%%", temp_sensor, humi_sensor);
       LCD_Write_string(0,ROW2, temp_msg);
    }
    
    if(UART1_getChar()=='q')
        break;
    if(tenKEY_getChar() =='\r' )
        break;    
    
  }
}


   

//-----------------------------------------------
void LED_Test(void)
{
  int i;
  Uart_Printf("Tachyon 2/3 Firmware Led Test    !!!\r\n");
  LCD_Clear();
  LCD_Write_string(0,ROW1,"LED Test"); // 첫번째 줄에 표시 
  
  while(1){
  led_blink();
   if(UART1_getChar()=='q')
        break;
   if(tenKEY_getChar() ==0x0d )break;    
  }
}
//-----------------------------------------------
void Lcd_Test(void)
{
  char i;
  Uart_Printf("Tachyon 2/3 Firmware LCD Test    !!!\r\n");
  
  for(i=0;i<55;i++)
    fillData_lcdBuffer (i, 0x55);
  
  while(1){
    LCD_Clear();
    Dly100us((void *)5000);
#if CHAR_LCD 
    LCD_Write_string(0,ROW1, "LCD Test..."); // 첫번째 줄에 표시 
#else
    gLCD_fill_write();
#endif
    
    Dly100us((void *)5000);
    
    if(UART1_getChar()=='q')
        break;
    if(tenKEY_getChar() =='\r' )break;    
  }
}

//-----------------------------------------------
void buzzer_test(void)
{
  int timer_count = 0;
  
  Uart_Printf("Tachyon 2/3 buzzer Test    !!!\r\n");
  
  LCD_Clear();
  Dly100us((void *)100);
  LCD_Write_string(0,ROW1, "BUZZER Test.."); // 첫번째 줄에 표시 

   while(1)
{

GPIO_SetBits(GPIOA, GPIO_Pin_8 ); //BUZZER  on
Dly100us((void *)500); 
GPIO_ResetBits(GPIOA, GPIO_Pin_8 ); //BUZZER   off
Dly100us((void *)500);
    
      if(UART1_getChar()=='q')
        break;
      if(tenKEY_getChar() =='\r' )break;    
}
}

//-----------------------------------------------
   
char gpsbuff[100];
// 아래것 주로사용함
//$GPGGA,-,-,-,-,-,-,-,-,-,-,*XX\r\n  
//$GPRMC,-,-,-,-,-,-,-,-,-,-,*XX\r\n  속도,DATA 노트단위
//$GPGSA,-,-,-,-,-,-,-,-,-,-,*XX\r\n  HDOP,수평위치 정밀도
void parsing(void)
{
  int i;
  char temp_msg[20];
  char hour,min,sec,gps_state;
  int mil_sec;
  char temp[8];
  char comma=0;
  long latitude,longitude;
  char ns,ew;
  for(i=0;i<100;i++){
    if(gpsbuff[i]=='$')break; 
  } 
  if(!strncmp(&gpsbuff[i],"$GPGGA",6)){ // 6개 비교 하여 같으면 0, 외 -1  
    i = i+5;
    while(i<100){
      if(gpsbuff[i++]==','){
        comma++;
        continue;
      } 
      if(comma == 1){// 시간 설정 
        i--;
        temp[0] = gpsbuff[i++];
        temp[1] = gpsbuff[i++];
        temp[2] = '\0';
        hour = atoi(temp);
        Uart_Printf("GPS hour: %d\n",hour);
        
        temp[0] = gpsbuff[i++];
        temp[1] = gpsbuff[i++];
        temp[2] = '\0';
        min = atoi(temp);
        Uart_Printf("GPS min: %d\n",min);
        
        temp[0] = gpsbuff[i++];
        temp[1] = gpsbuff[i++];
        temp[2] = '\0';
        sec = atoi(temp);
        Uart_Printf("GPS sec: %d\n",sec);
        i++;
        temp[0] = gpsbuff[i++];
        temp[1] = gpsbuff[i++];
        temp[2] = gpsbuff[i++];
        temp[3] = '\0';
        mil_sec = atoi(temp);
        
        Uart_Printf("GPS milsec:%d\n",mil_sec);
        
        sprintf(temp_msg,"T%2d:%2d:%2d", hour, min, sec);
        LCD_Write_string(0,ROW2, temp_msg); // 2번째 줄에 표시 
&