how to optimize code!!

Discussion in 'Embedded Systems and Microcontrollers' started by paddy611, Nov 27, 2012.

  1. paddy611

    Thread Starter New Member

    Oct 9, 2012
    25
    0
    Hello,

    I have to interface PIC micro controller with PLC over modbus.

    I have to read 120 number of holding registers of PLC and according to values received the port pin of micro controller is set or cleared.

    I have used 15 74HCT574 latch IC and all are connected to one port of micro controller.

    But in programming i am bit confused.

    I am using switch case. But as I mentioned I have got 120 process values that I need to compare, it increases the size of code with switch case.

    Please suggest any alternative to reduce the code size.

    thanks,
    paddy
     
  2. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    One would need to know what these 120 values are (what are the input?) and how that controls the output to make any suggestions.

    What comes in? What needs to go out?

    120 independent 8 bit variables has 960 bits for 9.7e+288 states. Hopefully there is a lot of redundant or unimportant information in those registers.
     
  3. paddy611

    Thread Starter New Member

    Oct 9, 2012
    25
    0
    The 120 holding registers contains process values and that are in between 0-100.

    I have to compare these values with some constant values i.e say 20,40 and >100.

    I have connected 8 port pins of micro controller to latch IC which are common to all 15 latch IC's and 15 pins are connected as a clock to enable the latch.

    So according to result of comparison the data is sent over the 8 pins that are connected to all latch IC's and by providing clock the expected latch is enabled.

    I am doing this using Switch case and by doing this way it increases the number of cases.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Still not clear. 120 input values, 15 output values, correct?

    Is each input value compared to the same range? How are these values stored, can they be in a nice array?

    Does each input value control a single bit in the output?
     
    Last edited: Nov 28, 2012
Loading...