16x04 Encoder from ATmega328 Micro Controller

Discussion in 'Embedded Systems and Microcontrollers' started by mkbutan, Jul 21, 2013.

  1. mkbutan

    Thread Starter Senior Member

    Sep 30, 2008
    270
    16
    Hi
    I am new to Programming and Microcontrollers
    I want to make 16 line Input to 4 Line output ENCODED by ATmega328 Microcontroller
    I have 2 New ATmega328 Microcontrollers (Without Bootloader).
    I have Arduino Board with ATmega328 Kit.
    do I need extra Programmer to Program the Atmega328 Microcontroller?
    if not. How to program the other ATmega328 with the ARDUINO 328 Kit???
    please Help

    The code I prepared are as follows:-

    Code ( (Unknown Language)):
    1. //16 x 4 Line Encoder
    2. // 16 input
    3. const int tr_01Pin =  1;  //  Input From Tr. BC547- 01
    4. const int tr_02Pin =  2;  //  Input From Tr. BC547- 02
    5. const int tr_03Pin =  3;  //  Input From Tr. BC547- 03
    6. const int tr_04Pin =  4;  //  Input From Tr. BC547- 04
    7. const int tr_05Pin =  5;  //  Input From Tr. BC547- 05
    8. const int tr_06Pin =  6;  //  Input From Tr. BC547- 06
    9. const int tr_07Pin =  9;  //  Input From Tr. BC547- 07
    10. const int tr_08Pin = 10;  //  Input From Tr. BC547- 08
    11. const int tr_09Pin = 11;  //  Input From Tr. BC547- 09
    12. const int tr_10Pin = 12;  //  Input From Tr. BC547- 10
    13. const int tr_11Pin = 13;  //  Input From Tr. BC547- 11
    14. const int tr_12Pin = 14;  //  Input From Tr. BC547- 12
    15. const int tr_13Pin = 15;  //  Input From Tr. BC547- 13
    16. const int tr_14Pin = 16;  //  Input From Tr. BC547- 14
    17. const int tr_15Pin = 17;  //  Input From Tr. BC547- 15
    18. const int tr_16Pin = 18;  //  Input From Tr. BC547- 16
    19.  
    20.  
    21. //BCD OUTPUT (A B C D as 0 0 0 0 - 1 1 1 1)
    22.  
    23.  
    24. const int OUT_A = 25;  // Output From A
    25. const int OUT_B = 26;  // Output From B
    26. const int OUT_C = 27;  // Output From C
    27. const int OUT_D = 28;  // Output From D
    28.  
    29.  
    30.  
    31.  
    32. void setup()
    33.  
    34.  
    35. {
    36. pinMode(tr_01Pin,INPUT);  //  0000
    37. pinMode(tr_02Pin,INPUT);  //  0001
    38. pinMode(tr_03Pin,INPUT);  //  0010
    39. pinMode(tr_04Pin,INPUT);  //  0011
    40. pinMode(tr_05Pin,INPUT);  //  0100
    41. pinMode(tr_06Pin,INPUT);  //  0101
    42. pinMode(tr_07Pin,INPUT);  //  0110
    43. pinMode(tr_08Pin,INPUT);  //  0111
    44. pinMode(tr_09Pin,INPUT);  //  1000
    45. pinMode(tr_10Pin,INPUT);  //  1001
    46. pinMode(tr_11Pin,INPUT);  //  1010
    47. pinMode(tr_12Pin,INPUT);  //  1011
    48. pinMode(tr_13Pin,INPUT);  //  1100
    49. pinMode(tr_14Pin,INPUT);  //  1101
    50. pinMode(tr_15Pin,INPUT);  //  1110
    51. pinMode(tr_16Pin,INPUT);  //  1111
    52.  
    53.  
    54. pinMode(OUT_A,OUTPUT);
    55. pinMode(OUT_B,OUTPUT);
    56. pinMode(OUT_C,OUTPUT);
    57. pinMode(OUT_D,OUTPUT);
    58.  
    59. }
    60.  
    61.  
    62. void loop()
    63.  
    64.  
    65. {
    66.  if(tr_01Pin == 0)  //  0000 = 00
    67.  {
    68.  OUT_D == 0;  // BCD OUTPUT
    69.  OUT_C == 0;  // BCD OUTPUT
    70.  OUT_B == 0;  // BCD OUTPUT
    71.  OUT_A == 0;  // BCD OUTPUT
    72.  }
    73.  
    74.  else
    75.  
    76.  if(tr_02Pin == 1)  //  0001 = 01
    77.  {
    78.  OUT_D == 1;  // BCD OUTPUT
    79.  OUT_C == 0;  // BCD OUTPUT
    80.  OUT_B == 0;  // BCD OUTPUT
    81.  OUT_A == 0;  // BCD OUTPUT
    82.  }
    83.  
    84.  else
    85.  
    86.  if(tr_03Pin == 1)  //  0010 = 02
    87.  {
    88.  OUT_D == 0;  // BCD OUTPUT
    89.  OUT_C == 1;  // BCD OUTPUT
    90.  OUT_B == 0;  // BCD OUTPUT
    91.  OUT_A == 0;  // BCD OUTPUT
    92.  }
    93.  
    94.  else
    95.  
    96.  if(tr_04Pin == 1)  //  0011 = 03
    97.  {
    98.  OUT_D == 1;  // BCD OUTPUT
    99.  OUT_C == 1;  // BCD OUTPUT
    100.  OUT_B == 0;  // BCD OUTPUT
    101.  OUT_A == 0;  // BCD OUTPUT
    102.  }
    103.  
    104.  else
    105.  
    106.  if(tr_05Pin == 1)  //  0100 = 04
    107.  {
    108.  OUT_D == 0;  // BCD OUTPUT
    109.  OUT_C == 0;  // BCD OUTPUT
    110.  OUT_B == 1;  // BCD OUTPUT
    111.  OUT_A == 0;  // BCD OUTPUT
    112.  }
    113.  
    114.  else
    115.  
    116.  if(tr_06Pin == 1)  //  0101 = 05
    117.  {
    118.  OUT_D == 1;  // BCD OUTPUT
    119.  OUT_C == 0;  // BCD OUTPUT
    120.  OUT_B == 1;  // BCD OUTPUT
    121.  OUT_A == 0;  // BCD OUTPUT
    122.  }
    123.  
    124.  else
    125.  
    126.  if(tr_07Pin == 1)  //  0110 = 06
    127.  {
    128.  OUT_D == 0;  // BCD OUTPUT
    129.  OUT_C == 1;  // BCD OUTPUT
    130.  OUT_B == 1;  // BCD OUTPUT
    131.  OUT_A == 0;  // BCD OUTPUT
    132.  }
    133.  
    134.  else
    135.  
    136.  if(tr_08Pin == 1)  //  0111 = 07
    137.  {
    138.  OUT_D == 1;  // BCD OUTPUT
    139.  OUT_C == 1;  // BCD OUTPUT
    140.  OUT_B == 1;  // BCD OUTPUT
    141.  OUT_A == 0;  // BCD OUTPUT
    142.  }
    143.  
    144.  else
    145.  
    146.  if(tr_09Pin == 1)  //  1000 =08
    147.  {
    148.  OUT_D == 0;  // BCD OUTPUT
    149.  OUT_C == 0;  // BCD OUTPUT
    150.  OUT_B == 0;  // BCD OUTPUT
    151.  OUT_A == 1;  // BCD OUTPUT
    152.  }
    153.  
    154.  else
    155.  
    156.  if(tr_10Pin == 1)  //  1001 = 09
    157.  {
    158.  OUT_D == 1;  // BCD OUTPUT
    159.  OUT_C == 0;  // BCD OUTPUT
    160.  OUT_B == 0;  // BCD OUTPUT
    161.  OUT_A == 1;  // BCD OUTPUT
    162.  }
    163.  
    164.  else
    165.  
    166.  if(tr_11Pin == 1)  //  1010 = 10
    167.  {
    168.  OUT_D == 0;  // BCD OUTPUT
    169.  OUT_C == 1;  // BCD OUTPUT
    170.  OUT_B == 0;  // BCD OUTPUT
    171.  OUT_A == 1;  // BCD OUTPUT
    172.  }
    173.  
    174.  else
    175.  
    176.  if(tr_12Pin == 1)  //  1011 = 11
    177.  {
    178.  OUT_D == 1;  // BCD OUTPUT
    179.  OUT_C == 1;  // BCD OUTPUT
    180.  OUT_B == 0;  // BCD OUTPUT
    181.  OUT_A == 1;  // BCD OUTPUT
    182.  }
    183.  
    184.  else
    185.  
    186.  if(tr_13Pin == 1)  //  1100 = 12
    187.  {
    188.  OUT_D == 0;  // BCD OUTPUT
    189.  OUT_C == 0;  // BCD OUTPUT
    190.  OUT_B == 1;  // BCD OUTPUT
    191.  OUT_A == 1;  // BCD OUTPUT
    192.  }
    193.  
    194.  else
    195.  
    196.  if(tr_14Pin == 1)  //  1101 = 12
    197.  {
    198.  OUT_D == 1;  // BCD OUTPUT
    199.  OUT_C == 0;  // BCD OUTPUT
    200.  OUT_B == 1;  // BCD OUTPUT
    201.  OUT_A == 1;  // BCD OUTPUT
    202.  }
    203.  
    204.  else
    205.  
    206.  if(tr_15Pin == 1)  //  1110 = 14
    207.  {
    208.  OUT_D == 0;  // BCD OUTPUT
    209.  OUT_C == 1;  // BCD OUTPUT
    210.  OUT_B == 1;  // BCD OUTPUT
    211.  OUT_A == 1;  // BCD OUTPUT
    212.  }
    213.  
    214.  else
    215.  
    216.  if(tr_16Pin == 1)  //  1111 = 15
    217.  {
    218.  OUT_D == 1;  // BCD OUTPUT
    219.  OUT_C == 1;  // BCD OUTPUT
    220.  OUT_B == 1;  // BCD OUTPUT
    221.  OUT_A == 1;  // BCD OUTPUT
    222.  }
    223.  
    224. }
    these are Written in ARDUINO IDE V1.0.5
    is this code ok for the 16x4 Encoder if not
    please help
     
    Last edited: Jul 21, 2013
Loading...