MPLAB C linking

Discussion in 'Programmer's Corner' started by powzoom, Nov 29, 2009.

  1. powzoom

    Thread Starter Active Member

    Jan 18, 2009
    41
    0
    I'm using MPLAB with the HI-TECH C light compiler. The chip is a 16F688.

    I'm trying to build a frequency meter. The code that controls the lcd screen works fine when all the code is in one file. If I copy/paste all the lcd code from my main .c to another .c and link it, it does not work. It will compile with no errors but the device fails to communicate with the lcd even though its the same exact code.

    Am I missing something? I took all the functions and definitions, put them in a separate .c file and tried to link it, #include "lcd.c" No errors, but it doesn't work.
     
  2. powzoom

    Thread Starter Active Member

    Jan 18, 2009
    41
    0
    I've done a few tests and I think I know what's wrong. Any changes to the ports are not working. Ex. Created a function to set RC4 high. Called it from main.c and it didn't work. However, I made a function that didn't try to change the ports, it just squared a number. That worked. So the code is linking, it's just not able to change the output pins for some reason.
     
  3. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    can you post your code??

    Did you use header files for each c file? Normally when linking files you should include the header file for each c file you want compiled with your project....

    so it should be "#include lcd.h" not "#include lcd.c"

    My .02
     
  4. powzoom

    Thread Starter Active Member

    Jan 18, 2009
    41
    0
    The main file

    Code ( (Unknown Language)):
    1.  
    2. #include <pic.h>
    3. //#include <p16F688.inc>
    4. #include <htc.h>
    5. #include "string.h"
    6.  
    7. __CONFIG (HS & WDTDIS & MCLRDIS & UNPROTECT);
    8.  
    9. #define PIC_CLK 20000000
    10. #include "delay.c"
    11. #include "LCD.c"
    12.  
    13.  
    14. //****************************************
    15. //****************************************
    16. // LC_Meter Defines ***********************
    17.  
    18. #define testbit_on(data,bitno) ((data>>bitno)&0x01)
    19. //#define CLEAR 0x01
    20.  
    21. //****************************************
    22. //****************************************
    23. // Functions ***********************
    24.  
    25.  
    26. void PIC_INIT(void);
    27.  
    28.  
    29. //****************************************
    30. //****************************************
    31. // Main ***********************
    32.  
    33. bit counting = 0;
    34. unsigned int sec = 0;
    35. unsigned int min = 0;
    36. unsigned long count = 0;
    37. unsigned long result = 0;
    38. unsigned int T1count = 0;
    39.  
    40. char run = 1;
    41.  
    42. void main ()
    43. {
    44.  
    45.         DelayMs(200);
    46.        
    47.         PIC_INIT();
    48.         LCD_INIT();
    49.  
    50.         OPTION = 0b00111000;
    51.  
    52.          // bit 4 sets prescale to WDT so bits<2:0> = 0 mean 1:1 ratio
    53.         T0IE = 1; //enable TMR0 overflow interrupts
    54.         ei(); // enable global interupts
    55.        
    56.         T1GSS = 1;
    57.         T1CON = 0b10100001; // set up timer1
    58.         TMR1IE = 1;
    59.         PEIE = 1;
    60.  
    61.         TMR0 = 0;
    62.         T1count = 0;
    63.         count = 0;
    64.         TMR0 = 0;
    65.  
    66.        
    67.    
    68.         LCD_CMD(CLEAR);
    69.         LCD_LONG(999999);
    70.         DelayS(2);
    71.         //counting = 1;
    72.  
    73.         RC4 = 1;
    74.         RC5 = 0;
    75.  
    76.         while (run==1)
    77.         {          
    78.             LCD_CMD(CLEAR);
    79.             LCD_STRING("Counting...");
    80.             result = 0;
    81.             counting = 1;
    82.             count = 0;
    83.             TMR0 = 0;  
    84.             T1count=0;
    85.             TMR1IF = 0;        
    86.             TMR1H = 0;
    87.             TMR1L = 0;
    88.             while (counting)
    89.             {
    90.             }
    91.  
    92.             LCD_CMD(CLEAR);
    93.             LCD_LONG(result);
    94.            
    95.             RC4 = RC4 ^ 1;  //XOR to swap from 1 to 0
    96.             RC5 = RC5 ^ 1;
    97.  
    98. //          LCD_Flip();
    99.  
    100.             DelayS(2);
    101.  
    102.         }
    103. }
    104.        
    105.  
    106. void PIC_INIT()
    107. {
    108.         // ADC off, all digital I/O
    109.         ANSEL = 0;
    110.         CMCON0=0x07;
    111.          
    112.         // PORT direction register
    113.         TRISA = 0b00000100;
    114.         TRISC = 0b00000000;
    115. }
    116.  
    117.  
    118.  
    119. //****************************************
    120. //****************************************
    121. // Interrupt stuff ***********************
    122.  
    123.  
    124.  
    lcd.c

    Code ( (Unknown Language)):
    1.  
    2. #ifndef LCD_C
    3. #define LCD_C
    4.  
    5.  
    6. #include "lcd.h"
    7.  
    8. //*************************************
    9. //************************************
    10. // LCD STUFF *************************
    11.  
    12. extern void LCD_INIT(void)
    13. {
    14.         LCD_CLR_DATA();
    15.         LCD_CLR_CONTROL();
    16.  
    17.         // wait for lcd
    18.         DelayMs(100);
    19.         //reset lcd
    20.         P_DATA = (P_DATA & data_mask) | 0x03;
    21.         //P_DATA = 0x03;
    22.         P_CONTROL = 0x00;
    23.         LCD_ENABLE();
    24.         DelayMs(20);
    25.         // do it 2 more times
    26.         LCD_ENABLE();
    27.         DelayMs(15);
    28.         LCD_ENABLE();
    29.         DelayMs(10);
    30.         // set 4-bit mode
    31.         P_DATA = (P_DATA & data_mask) | 0x02;
    32.         //P_DATA = 0x02;
    33.         LCD_ENABLE();
    34.         DelayMs(10);
    35.  
    36.         // now in 4-bit mode
    37.         LCD_CMD(0x28); // 2line 4-bit
    38.         LCD_CMD(0x08); // Display Off
    39.         LCD_CMD(0x01); // Clear
    40.         LCD_CMD(0x06); // Set Entry
    41.         LCD_CMD(0x0C); // Display on, blink and cursor off
    42.         LCD_CMD(0x80); // Set DDRAM address
    43.        
    44. }
    45.  
    46. extern void LCD_CLR_CONTROL()
    47. {
    48.     RS = 0;
    49.     EN = 0;
    50. }
    51.  
    52. extern void LCD_CLR_DATA()
    53. {
    54.     D4 = 0;
    55.     D5 = 0;
    56.     D6 = 0;
    57.     D7 = 0;
    58.  
    59. }
    60.  
    61. extern void LCD_ENABLE()
    62. {
    63.         EN=1;
    64.         asm("nop");
    65.         EN=0;
    66.         asm("nop");
    67. }
    68.  
    69.  
    70. extern void LCD_CMD(unsigned char cmd)
    71. {
    72.         unsigned char temp = 0;
    73.  
    74.         // swap then xor to get only high nibble
    75.         temp = cmd;
    76.         temp = (temp >> 4) | (temp << 4);
    77.         temp = temp & 0x0F;
    78.         P_DATA = (P_DATA & data_mask) | temp;
    79.         //P_DATA = temp;
    80.         RS=0;
    81.         LCD_ENABLE();
    82.        
    83.         // now the lower nibble
    84.         temp = cmd;
    85.         temp = temp & 0x0F;
    86.         P_DATA = (P_DATA & data_mask) | temp;
    87.         //P_DATA = temp;
    88.         RS=0;
    89.         LCD_ENABLE();
    90.  
    91.         //add a delay
    92.         DelayMs(2);                
    93.  
    94. }
    95.  
    96. extern void LCD_CHAR(unsigned char cmd)
    97. {
    98.         unsigned char temp = 0;
    99.  
    100.         // swap then xor to get only high nibble
    101.         temp = cmd;
    102.         temp = (temp >> 4) | (temp << 4);
    103.         temp = temp & 0x0F;
    104.         P_DATA = (P_DATA & data_mask) | temp;
    105.         //P_DATA = temp;
    106.         RS=1;
    107.         LCD_ENABLE();
    108.        
    109.         // now the lower nibble
    110.         temp = cmd;
    111.         temp = temp & 0x0F;
    112.         P_DATA = (P_DATA & data_mask) | temp;
    113.         //P_DATA = temp;
    114.         RS=1;
    115.         LCD_ENABLE();
    116.  
    117.         //add a delay
    118.         DelayMs(2);                
    119.         //set RS back to 0
    120.         RS=0;
    121.  
    122. }
    123.  
    124. extern void LCD_STRING(unsigned char *var)
    125. {
    126.      while(*var)              //till string ends
    127.        LCD_CHAR(*var++);  //send characters one by one
    128. }
    129.  
    130. extern void LCD_INT(unsigned int num)
    131. {
    132.         //        Break down the original number into the thousands, hundreds, tens,
    133.         //        and ones places and then immediately write that value to the LCD
    134.        
    135.         unsigned char tenthousands = 0;
    136.         unsigned char thousands = 0;
    137.         unsigned char hundreds = 0;
    138.         unsigned char tens        = 0;
    139.         unsigned char ones = 0;
    140.  
    141.         tenthousands = num / 10000;
    142.         LCD_CHAR(tenthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    143.  
    144.         thousands = (num - tenthousands*10000)/1000;
    145.         LCD_CHAR(thousands + 0x030);
    146.  
    147.         hundreds = (num - tenthousands*10000 - thousands*1000)/100;
    148.         LCD_CHAR(hundreds + 0x030);
    149.  
    150.         tens = (num - tenthousands*10000 - thousands*1000 - hundreds*100)/10;
    151.         LCD_CHAR(tens + 0x030);
    152.  
    153.         ones = (num - tenthousands*10000 - thousands*1000 - hundreds*100 - tens*10);
    154.         LCD_CHAR(ones + 0x030);
    155. }
    156.  
    157. extern void LCD_LONG(unsigned long num)
    158. {
    159.         //        Break down the original number into the thousands, hundreds, tens,
    160.         //        and ones places and then immediately write that value to the LCD
    161.        
    162.         unsigned char billions = 0;
    163.         unsigned char hundredmillions = 0;
    164.         unsigned char tenmillions = 0;
    165.         unsigned char millions = 0;
    166.         unsigned char hundredthousands = 0;
    167.         unsigned char tenthousands = 0;
    168.         unsigned char thousands = 0;
    169.         unsigned char hundreds = 0;
    170.         unsigned char tens   = 0;
    171.         unsigned char ones = 0;
    172.  
    173.         unsigned long temp = num;
    174.  
    175.         billions = num / 1000000000;
    176.         LCD_CHAR(billions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    177.         temp = temp - (billions*1000000000); //temp = num - last decimal digit
    178.  
    179.         hundredmillions = temp / 100000000;
    180.         LCD_CHAR(hundredmillions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    181.         temp = temp - (hundredmillions*100000000); //temp = num - last 2decimal digit
    182.  
    183.         tenmillions = temp / 10000000;
    184.         LCD_CHAR(tenmillions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    185.         temp = temp - (tenmillions*10000000); //temp = num - last 3decimal digit
    186.    
    187.         millions = temp/ 1000000;
    188.         LCD_CHAR(millions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    189.         temp = temp - (millions*1000000); //temp = num - last 4 digits
    190.    
    191.         hundredthousands = temp / 100000;
    192.         LCD_CHAR(hundredthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    193.         temp = temp - (hundredthousands*100000);
    194.  
    195.         tenthousands = temp / 10000;
    196.         LCD_CHAR(tenthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    197.         temp = temp - (tenthousands*10000);
    198.  
    199.         thousands = temp/1000;
    200.         LCD_CHAR(thousands + 0x030);
    201.         temp = temp - (thousands*1000);
    202.  
    203.         hundreds = temp/100;
    204.         LCD_CHAR(hundreds + 0x030);
    205.         temp = temp - (hundreds*100);
    206.  
    207.         tens = temp/10;
    208.         LCD_CHAR(tens + 0x030);
    209.         temp = temp - (tens*10);
    210.  
    211.         ones = temp;
    212.         LCD_CHAR(ones + 0x030);
    213. }
    214.  
    215.  
    216. #endif
    lcd.h

    Code ( (Unknown Language)):
    1.  
    2.  
    3.  
    4. #ifndef LCD_H
    5. #define LCD_H
    6.  
    7. //****************************************
    8. //****************************************
    9. // LCD Defines ***********************
    10. #define MAXPOSX      16
    11. #define MAXPOSY       2
    12.  
    13. #define RS      RA0
    14. #define RW      RA1
    15. #define EN      RA2
    16.  
    17. #define D4      RC0
    18. #define D5      RC1
    19. #define D6      RC2
    20. #define D7      RC3
    21.  
    22. #define P_DATA         PORTC
    23. #define data_mask       0b11110000  //used data ports on RC are 0, rest 1
    24. #define P_CONTROL       PORTA
    25. #define control_mask    0b11111100 // used control ports on RA are 0
    26.  
    27. #define CLEAR 0x01
    28.  
    29. /////////////////////////////
    30.  
    31.  
    32. extern void LCD_INIT(void);
    33. extern void LCD_CHAR(unsigned char cmd);
    34. extern void LCD_STRING(unsigned char *var);
    35. extern void LCD_CMD(unsigned char cmd);
    36. extern void LCD_ENABLE();
    37. extern void LCD_INT(unsigned int num);
    38. extern void LCD_LONG(unsigned long num);
    39. extern void LCD_CLR_CONTROL();
    40. extern void LCD_CLR_DATA();
    41.  
    42. #endif
     
  5. powzoom

    Thread Starter Active Member

    Jan 18, 2009
    41
    0
    And the original working code

    Code ( (Unknown Language)):
    1.  
    2. #include <pic.h>
    3. //#include <p16F688.inc>
    4. #include <htc.h>
    5. #include "string.h"
    6.  
    7. __CONFIG (HS & WDTDIS & MCLRDIS & UNPROTECT);
    8.  
    9. #define PIC_CLK 20000000
    10. #include "delay.c"
    11. #include "test2.c"
    12.  
    13. //****************************************
    14. //****************************************
    15. // LCD Defines ***********************
    16. #define MAXPOSX             16
    17. #define MAXPOSY              2
    18.  
    19. #define RS                 RA0
    20. //RW to ground
    21. #define EN                RA1
    22.  
    23. #define D4                RC0
    24. #define D5                RC1
    25. #define D6                RC2
    26. #define D7                RC3
    27.  
    28. #define P_DATA         PORTC
    29. #define data_mask       0b11110000  //used data ports on RC are 0, rest 1
    30. #define P_CONTROL       PORTA
    31. #define control_mask    0b11111100 // used control ports on RA are 0
    32.  
    33. #define CLEAR 0x01
    34.  
    35. //****************************************
    36. //****************************************
    37. // LC_Meter Defines ***********************
    38.  
    39. #define testbit_on(data,bitno) ((data>>bitno)&0x01)
    40.  
    41.  
    42.  
    43.  
    44.  
    45. //****************************************
    46. //****************************************
    47. // Functions ***********************
    48.  
    49. void LCD_INIT(void);
    50. void PIC_INIT(void);
    51. void Clear(void);
    52. void LCD_CHAR(unsigned char cmd);
    53. void LCD_STRING(unsigned char *var);
    54. void LCD_CMD(unsigned char cmd);
    55. void LCD_ENABLE();
    56. void LCD_INT(unsigned int num);
    57. void LCD_LONG(unsigned long num);
    58. void LCD_CLR_CONTROL();
    59. void LCD_CLR_DATA();
    60.  
    61.  
    62. //****************************************
    63. //****************************************
    64. // Main ***********************
    65.  
    66. bit counting = 0;
    67. unsigned int sec = 0;
    68. unsigned int min = 0;
    69. unsigned long count = 0;
    70. unsigned long result = 0;
    71. unsigned int T1count = 0;
    72.  
    73. void main ()
    74. {
    75.         char run = 1;
    76.  
    77.         DelayMs(200);
    78.        
    79.         PIC_INIT();
    80.         LCD_INIT();
    81.  
    82.  
    83.         OPTION = 0b00111000;
    84.  
    85.  
    86.         // bit 4 sets prescale to WDT so bits<2:0> = 0 mean 1:1 ratio
    87.         T0IE = 1; //enable TMR0 overflow interrupts
    88.         ei(); // enable global interupts
    89.        
    90.         T1GSS = 1;
    91.         T1CON = 0b10100001; // set up timer1
    92.         TMR1IE = 1;
    93.         PEIE = 1;
    94.  
    95.         TMR0 = 0;
    96.         T1count = 0;
    97.         count = 0;
    98.         TMR0 = 0;
    99.        
    100.    
    101.         LCD_CMD(CLEAR);
    102.         long k = times2(4999);
    103.         LCD_LONG(k);
    104.         DelayS(2);
    105.         //counting = 1;
    106.  
    107.         RC4 = 1;
    108.         RC5 = 0;
    109.  
    110.         while (run==1)
    111.         {          
    112.             LCD_CMD(CLEAR);
    113.             LCD_STRING("Counting...");
    114.             result = 0;
    115.             counting = 1;
    116.             count = 0;
    117.             TMR0 = 0;  
    118.             T1count=0;
    119.             TMR1IF = 0;        
    120.             TMR1H = 0;
    121.             TMR1L = 0;
    122.             while (counting)
    123.             {
    124.             }
    125.  
    126.             LCD_CMD(CLEAR);
    127.             LCD_LONG(result);
    128.            
    129.             RC4 = RC4 ^ 1;  //XOR to swap from 1 to 0
    130.             RC5 = RC5 ^ 1;
    131.  
    132.             DelayS(2);
    133.  
    134.         }
    135. }
    136.        
    137.  
    138. void PIC_INIT()
    139. {
    140.         // ADC off, all digital I/O
    141.         ANSEL = 0;
    142.         CMCON0=0x07;
    143.          
    144.         // PORT direction register
    145.         TRISA = 0b00000100;
    146.         TRISC = 0b00000000;
    147. }
    148.  
    149. //*************************************
    150. //************************************
    151. // LCD STUFF *************************
    152.  
    153. void LCD_INIT()
    154. {
    155.         LCD_CLR_DATA();
    156.         LCD_CLR_CONTROL();
    157.  
    158.         // wait for lcd
    159.         DelayMs(100);
    160.         //reset lcd
    161.         P_DATA = (P_DATA & data_mask) | 0x03;
    162.         //P_DATA = 0x03;
    163.         P_CONTROL = 0x00;
    164.         LCD_ENABLE();
    165.         DelayMs(20);
    166.         // do it 2 more times
    167.         LCD_ENABLE();
    168.         DelayMs(15);
    169.         LCD_ENABLE();
    170.         DelayMs(10);
    171.         // set 4-bit mode
    172.         P_DATA = (P_DATA & data_mask) | 0x02;
    173.         //P_DATA = 0x02;
    174.         LCD_ENABLE();
    175.         DelayMs(10);
    176.  
    177.         // now in 4-bit mode
    178.         LCD_CMD(0x28); // 2line 4-bit
    179.         LCD_CMD(0x08); // Display Off
    180.         LCD_CMD(0x01); // Clear
    181.         LCD_CMD(0x06); // Set Entry
    182.         LCD_CMD(0x0C); // Display on, blink and cursor off
    183.         LCD_CMD(0x80); // Set DDRAM address
    184.        
    185. }
    186.  
    187. void LCD_CLR_CONTROL()
    188. {
    189.     RS = 0;
    190.     EN = 0;
    191. }
    192.  
    193. void LCD_CLR_DATA()
    194. {
    195.     D4 = 0;
    196.     D5 = 0;
    197.     D6 = 0;
    198.     D7 = 0;
    199.  
    200. }
    201.  
    202. void LCD_ENABLE()
    203. {
    204.         EN=1;
    205.         asm("nop");
    206.         EN=0;
    207.         asm("nop");
    208. }
    209.  
    210.  
    211. void LCD_CMD(unsigned char cmd)
    212. {
    213.         unsigned char temp = 0;
    214.  
    215.         // swap then xor to get only high nibble
    216.         temp = cmd;
    217.         temp = (temp >> 4) | (temp << 4);
    218.         temp = temp & 0x0F;
    219.         P_DATA = (P_DATA & data_mask) | temp;
    220.         //P_DATA = temp;
    221.         RS=0;
    222.         LCD_ENABLE();
    223.        
    224.         // now the lower nibble
    225.         temp = cmd;
    226.         temp = temp & 0x0F;
    227.         P_DATA = (P_DATA & data_mask) | temp;
    228.         //P_DATA = temp;
    229.         RS=0;
    230.         LCD_ENABLE();
    231.  
    232.         //add a delay
    233.         DelayMs(2);                
    234.  
    235. }
    236.  
    237. void LCD_CHAR(unsigned char cmd)
    238. {
    239.         unsigned char temp = 0;
    240.  
    241.         // swap then xor to get only high nibble
    242.         temp = cmd;
    243.         temp = (temp >> 4) | (temp << 4);
    244.         temp = temp & 0x0F;
    245.         P_DATA = (P_DATA & data_mask) | temp;
    246.         //P_DATA = temp;
    247.         RS=1;
    248.         LCD_ENABLE();
    249.        
    250.         // now the lower nibble
    251.         temp = cmd;
    252.         temp = temp & 0x0F;
    253.         P_DATA = (P_DATA & data_mask) | temp;
    254.         //P_DATA = temp;
    255.         RS=1;
    256.         LCD_ENABLE();
    257.  
    258.         //add a delay
    259.         DelayMs(2);                
    260.         //set RS back to 0
    261.         RS=0;
    262.  
    263. }
    264.  
    265. void LCD_STRING(unsigned char *var)
    266. {
    267.      while(*var)              //till string ends
    268.        LCD_CHAR(*var++);  //send characters one by one
    269. }
    270.  
    271. void LCD_INT(unsigned int num)
    272. {
    273.         //        Break down the original number into the thousands, hundreds, tens,
    274.         //        and ones places and then immediately write that value to the LCD
    275.        
    276.         unsigned char tenthousands = 0;
    277.         unsigned char thousands = 0;
    278.         unsigned char hundreds = 0;
    279.         unsigned char tens        = 0;
    280.         unsigned char ones = 0;
    281.  
    282.         tenthousands = num / 10000;
    283.         LCD_CHAR(tenthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    284.  
    285.         thousands = (num - tenthousands*10000)/1000;
    286.         LCD_CHAR(thousands + 0x030);
    287.  
    288.         hundreds = (num - tenthousands*10000 - thousands*1000)/100;
    289.         LCD_CHAR(hundreds + 0x030);
    290.  
    291.         tens = (num - tenthousands*10000 - thousands*1000 - hundreds*100)/10;
    292.         LCD_CHAR(tens + 0x030);
    293.  
    294.         ones = (num - tenthousands*10000 - thousands*1000 - hundreds*100 - tens*10);
    295.         LCD_CHAR(ones + 0x030);
    296. }
    297.  
    298. void LCD_LONG(unsigned long num)
    299. {
    300.         //        Break down the original number into the thousands, hundreds, tens,
    301.         //        and ones places and then immediately write that value to the LCD
    302.        
    303.         unsigned char billions = 0;
    304.         unsigned char hundredmillions = 0;
    305.         unsigned char tenmillions = 0;
    306.         unsigned char millions = 0;
    307.         unsigned char hundredthousands = 0;
    308.         unsigned char tenthousands = 0;
    309.         unsigned char thousands = 0;
    310.         unsigned char hundreds = 0;
    311.         unsigned char tens   = 0;
    312.         unsigned char ones = 0;
    313.  
    314.         unsigned long temp = num;
    315.  
    316.         billions = num / 1000000000;
    317.         LCD_CHAR(billions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    318.         temp = temp - (billions*1000000000); //temp = num - last decimal digit
    319.  
    320.         hundredmillions = temp / 100000000;
    321.         LCD_CHAR(hundredmillions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    322.         temp = temp - (hundredmillions*100000000); //temp = num - last 2decimal digit
    323.  
    324.         tenmillions = temp / 10000000;
    325.         LCD_CHAR(tenmillions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    326.         temp = temp - (tenmillions*10000000); //temp = num - last 3decimal digit
    327.    
    328.         millions = temp/ 1000000;
    329.         LCD_CHAR(millions + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    330.         temp = temp - (millions*1000000); //temp = num - last 4 digits
    331.    
    332.         hundredthousands = temp / 100000;
    333.         LCD_CHAR(hundredthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    334.         temp = temp - (hundredthousands*100000);
    335.  
    336.         tenthousands = temp / 10000;
    337.         LCD_CHAR(tenthousands + 0x030);  //add 0x30 b/c thats where ascii 0 starts
    338.         temp = temp - (tenthousands*10000);
    339.  
    340.         thousands = temp/1000;
    341.         LCD_CHAR(thousands + 0x030);
    342.         temp = temp - (thousands*1000);
    343.  
    344.         hundreds = temp/100;
    345.         LCD_CHAR(hundreds + 0x030);
    346.         temp = temp - (hundreds*100);
    347.  
    348.         tens = temp/10;
    349.         LCD_CHAR(tens + 0x030);
    350.         temp = temp - (tens*10);
    351.  
    352.         ones = temp;
    353.         LCD_CHAR(ones + 0x030);
    354. }
    355.  
    356. //****************************************
    357. //****************************************
    358. // Interrupt stuff ***********************
    359.  
    360.  
    361.  
     
  6. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    I'm surprised it doesn't work yet throws up no errors when compiled but in any case you could try the following.
    Add "#include <htc.h>" to your lcd.c file,
    Add '#include "lcd.h" to your main file
    Do not include lcd.c in the main file but rather add it to the source file list in MPLAB
     
Loading...