c - Need explain a code in embedded program -


i new embedded programming, i'm examining code below , trying understand how work, got stuck.

the program used count , print out numbers 0 9.

so can please explain line const uint8_t ? why need array of heximal number here?

#include <avr/io.h> #include <util/delay.h> #include "debug.h"   const uint8_t segments[10] = {0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe4,0xfe,0xf6};  int main(void) {     uint8_t i=0; //s     int g;      init_debug_uart0();     /* set port pins outputs */     ddra = 0xff;     (;;) {          porta = segments[i];          printf("%d\n\r",i);          _delay_ms(1000);          if (i >=9) {             fprintf(stderr , "count overflow\n\r"); = 0;             scanf("%d", &g);         }else              i++;     } } 

and final question, know sources read embedded programming? i'm learning iimatto, 8-bits processor , has 32-registers, designed in harvard architecture , has 1 level pipeline.

the const uint8_t segments[10] = {0xfc,0x60,0xda, ... simple defines constant 10-byte array of bytes.

code not need array of hexadecimal, have been decimal.

but consider benefit of

0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe4,0xfe,0xf6 // versus 252,96,218,... 

a casual inspection shows number of bits set in each byte is

6,2,5,5,... 

this happens match number of segments set in 7-segment display of digits 0,1,2,3 ...
closer inspection of bits set detail bit activate segment.

other methods employed mapping of 7-segment digit, showing data in hexadecimal 1 step closer decimal.


perhaps code (the proper segment mapping tbd).

typedef enum  {   led7_a       = 1 << 0,   led7_b       = 1 << 1,   led7_c       = 1 << 2,   led7_d       = 1 << 3,   led7_e       = 1 << 4,   led7_f       = 1 << 5,   led7_g       = 1 << 6,   led7_dp      = 1 << 7   } led7_segment_t;  /* **************************************************************************** 7 segment pattern  layout   aaa  f   b  f   b   ggg  e   c  e   c   ddd dp **************************************************************************** */ const uint8_t segments[] = {   /*'0*/ led7_a | led7_b | led7_c | led7_d | led7_e | led7_f         ,   /*'1*/          led7_b | led7_c                                    ,   /*'2*/ led7_a | led7_b |          led7_d | led7_e |          led7_g,   /*'3*/ led7_a | led7_b | led7_c | led7_d |                   led7_g,   /*'4*/          led7_b | led7_c |                   led7_f | led7_g,   /*'5*/ led7_a |          led7_c | led7_d |          led7_f | led7_g,   /*'6*/ led7_a |          led7_c | led7_d | led7_e | led7_f | led7_g,   /*'7*/ led7_a | led7_b | led7_c                                    ,   /*'8*/ led7_a | led7_b | led7_c | led7_d | led7_e | led7_f | led7_g,   /*'9*/ led7_a | led7_b | led7_c | led7_d |          led7_f | led7_g}; 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -