PandA-2024.02
led_example.c
Go to the documentation of this file.
1 #include "leds_ctrl.h"
2 #include "sw_ctrl.h"
3 #include "btn_ctrl.h"
4 #include "sevensegments_ctrl.h"
5 
6 unsigned char convert_char_digit_2_sseg(char c)
7 {
8  static unsigned char table[] = {63/*0*/, 6/*1*/, 91/*2*/, 79/*3*/, 102/*4*/, 109/*5*/, 125/*6*/, 7/*7*/, 127/*8*/, 111/*9*/};
9  return table[c-'0'];
10 }
11 
13 {
14  _Bool terminate = 0;
15  char a, b, c, d, e, f, g;
16  do
17  {
18  unsigned short val = sw_ctrl();
19  unsigned long long sseg_val = ((unsigned long long)DOT_BITVALUE) << 4*8;
20 
21  short int low_byte = val & 255;
22  short int high_byte = val >> 8;
23  for ( a = '0' - 1; high_byte >= 0; high_byte -= 100 ) ++a;
24  for ( b = '9' + 1; high_byte < 0; high_byte += 10 ) --b;
25  c = high_byte + '0';
26  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(c))<<4*8;
27  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(b))<<5*8;
28  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(a))<<6*8;
30  d = (low_byte * 10)>>8;
31  low_byte = low_byte * 10 - d*256;
32  d = '0' + d;
33  e = (low_byte * 10)>>8;
34  low_byte = low_byte * 10 - e*256;
35  e = '0' + e;
36  f = (low_byte * 10)>>8;
37  low_byte = low_byte * 10 - f*256;
38  f = '0' + f;
39  g = (low_byte * 10)>>8;
40  low_byte = low_byte * 10 - g*256;
41  g = '0' + g;
42  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(d))<<3*8;
43  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(e))<<2*8;
44  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(f))<<1*8;
45  sseg_val |= ((unsigned long long)convert_char_digit_2_sseg(g))<<0*8;
46  leds_ctrl(val);
47  sevensegments_ctrl(sseg_val,~0ULL);
48  terminate = (btn_ctrl() & BUTTON_UP) != 0;
49  } while(!terminate);
50 }
unsigned char btn_ctrl()
Definition: btn_ctrl.c:3
void leds_ctrl(unsigned short val)
Definition: leds_ctrl.c:3
unsigned short sw_ctrl()
Definition: sw_ctrl.c:2
unsigned char convert_char_digit_2_sseg(char c)
Definition: led_example.c:6
void led_example()
Definition: led_example.c:12
#define BUTTON_UP
Definition: btn_ctrl.h:4
void sevensegments_ctrl(unsigned long long val, unsigned long long mask)
#define DOT_BITVALUE

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13