CAFE

한국직업능력교육원

[Arduino 실습 5] FND 구구단 & TIM2

작성자송명규|작성시간26.06.08|조회수6 목록 댓글 0



// Sys Lib

#include <stdio.h>

#include <string.h>

#include <stdlib.h>

 

// Arduino API

#include <MsTimer2.h>

 

// My Lib

#include <My_Arduino_GPIO_Lib_V1_8.h>

//#include <My_Arduino_FND_Lib_V2_7.h>

 

// PRJ Lib

#define GPIO_IF  1

#define Digit_4  2

//#define Fnd_Dis  3

#define Fnd_Led_Dis 4

//#define En_Font_Dis 5

#include "fnd_dis.h"

 

uint16_t cnt16 = 1234;

uint16_t t_loop = 0;

uint16_t buf;

uint8_t led_cnt=0;

char d_buf[50];

 

#define Arduino_Mode   1

#define HW_Uart_mode   2

extern int out_dev_set_mode;

#include <My_MCU_Printf_Lib_V2_6.h>

 

struct TIME

{

  int tm_loop;

  char sec;

  char min;

  char hour;

  uint8_t dan;

  int8_t gu;

  uint8_t mul;

}time = {0, 0, 17, 15,0,0,0};

struct TIME *tm = &time;



void setup() {

  int hj = 0;

  // put your setup code here, to run once:

  //DDRD = DDRB = 0xff;

  for(int i = 0; i<= 7;)

  { // LED + FND DIR Set  

    pinMode(LED_pin[i], OUTPUT);

    Led_Byte_Out(0xff); // init

    i++;

  }

 

  pinMode(x1000, OUTPUT);  

  pinMode(x100, OUTPUT);

  pinMode(x10, OUTPUT);

  pinMode(x1, OUTPUT);

  #if Fnd_Led_Dis

    pinMode(led_scan_pin, OUTPUT);

  #endif  

 

  Serial.begin(115200);

  out_dev_set_mode = HW_Uart_IF_Mode;

 

  Flag_sts.Dp_X100_Flag = 1;

 

  // Timer2 Interrupt

  MsTimer2::set(1, tm2_irq);

  MsTimer2::start();

 

}

 

void tm2_irq()

{

  fnd_led_dis((*tm).dan*1000 + (*tm).gu*100 + (*tm).dan * (*tm).gu, (*tm).dan * (*tm).gu);        

}

void loop() {

  // put your main code here, to run repeatedly:

  for(tm -> dan = 1; tm -> dan <= 9; tm -> dan++)

  {

    for((*tm).gu = 1; (*tm).gu <= 9; (*tm).gu++)

    {

      //uart

      dev_printf("구구단 = %d X %d = %d\r\n", (*tm).dan, (*tm).gu, (*tm).dan * (*tm).gu);                  

      _delay_ms(1000);

    }

    Serial.println("");

  }

 

/*  

 _delay_ms(1);

 tm -> tm_loop++;

 if(tm ->tm_loop > 990) // 1sec chk sum

 {// if-1

   tm -> tm_loop = 0;

   tm -> sec++;

  if((*tm).sec > 59)  // 1 min chk sum

  { //if-2

    tm -> sec = 0;

    time.min++;

    if(tm -> min > 59) // 1 Hour Chk sum

    { // if-3

     (*tm).min = 0;

     tm -> hour++;

     if((*tm).hour > 23) time.hour = 0;

    } //if-3-end

  } // if-2-end

 

  Flag_sts.Dp_X1_Flag = !Flag_sts.Dp_X1_Flag;

  Flag_sts.Dp_X100_Flag = !Flag_sts.Dp_X1_Flag;  

  // printf

  dev_printf("Now Time = %d : %d : %d\r\n", (*tm).hour, time.min, tm ->sec);

 } // if-1-end

*/

 

/*  

  t_loop++;

  if(t_loop > 200)

  {

    t_loop = 0;

    (cnt16 > 2000) ? cnt16 = 1234 : cnt16++;  

    if(cnt16 % 20 == 0) led_cnt++;//buf = cnt16;

    Flag_sts.Dp_X1_Flag = !Flag_sts.Dp_X1_Flag;

 

    //Serial.print("Now Cnt = ");

    //Serial.println(cnt16);  // hi

   

    //Hi

    dev_printf("Now Cnt= %d\r\n", cnt16);

 

    // mid

    // sprintf(d_buf,"Now Cnt= %4d\r\n", cnt16);

    // Serial.print(d_buf);

 

    // Low

    // Serial.write(cnt16 /1000 + 0x30);

    // Serial.write(cnt16 %1000/100 + '0');

    // Serial.write(cnt16 %100/10 + 48);

    // Serial.write(cnt16 %10 + 0x30);

    // Serial.println("");

  }

*/

 

/*

  #if En_Font_Dis

    fnd_dis_en_font(H,E,L,P);

  #elif Fnd_Led_Dis  

    //fnd_led_dis(tm -> min * 100 + tm ->sec, tm -> sec);//map(cnt16, 1234, 2000, 0, 255));

    fnd_led_dis((*tm).dan*1000 + (*tm).gu*100 + (*tm).dan * (*tm).gu, (*tm).dan * (*tm).gu);//map(cnt16, 1234, 2000, 0, 255));

  #elif Fnd_Dis  

    fnd_dis(cnt16);

  #endif

*/  

}




다음검색
현재 게시글 추가 기능 열기

댓글

댓글 리스트
맨위로

카페 검색

카페 검색어 입력폼