Help needed for programming of pic16f877a using C in MPLAB

Discussion in 'Embedded Systems and Microcontrollers' started by bhargav_17789, Apr 15, 2010.

  1. bhargav_17789

    Thread Starter New Member

    Apr 15, 2010
    3
    0
    Hi,

    I have written a program for 16f877a in MPLAB. And when i build it, it shows that "Build Failed", but does not show any errors. So i tried to compile my program using HTPIC and in that i am getting following errors

    ::Can't find 0x75 words for psect rbss_0 in segment BANK0 (error)
    ::Can't find 0x10 words for psect rdata_0 in segment BANK0 (error)
    ::Can't find 0x7 words for psect temp in segment COMBANK (error)
    ::Can't find 0x2 words (0x2 withtotal) for psect code_ptr in segment BANK0 (error)

    I think these are the error notifying me that my bank0 is full. Can anyone tell me how can i change my bank so that i can get rid of these errors ....

    And also help me with MPLAB - It does not show me any errors due it just says build failed ....

    Thank You ...
     
  2. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Post your code, you probably have the errors suppressed that is why they are not showing.... post your code and this will help determining the problem.

    B. Morse
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    You can set the levels of warnings and errors displayed in MPLAB under the menu "Project/Build Options ../project".

    Also make sure that you have the correct device type (chip) selected in the menu "Configure/Select Device...".

    If that doesn't fix it do as BMorse suggests and post your code. Make sure you go into advanced editing mode and use the code tags (#) to make your code more readable.
     
  4. bhargav_17789

    Thread Starter New Member

    Apr 15, 2010
    3
    0
    #include<stdio.h>
    #include<pic.h>

    #define col1 RD0
    #define col2 RD1
    #define col3 RD2
    #define col4 RD3
    #define row1 RD4
    #define row2 RD5
    #define row3 RD6
    #define row4 RD7

    #define password1 1234
    #define count_limit 10

    int password,pass_c=0;

    char keypad[4][4]={ {'1','2','3','4'},
    {'5','6','7','8'},
    {'9','0','B','E'},
    {'X','R','S','F'} };

    void lcd_command(int w);
    void lcd_display(char w);
    void lcd_init(void);
    void delay1(void);
    char int_asci(int w);
    int asci_int(char w);
    void display_status(int count);
    char key_scan(void);
    void pass(int w,int pass_c);
    void pass_back(int w,int pass_c);
    void pass_check(void);
    void motor_delay(void);
    void display_full(void);
    void display_open(void);
    void car_pass_delay(void);


    void main()
    {
    int n,count,i,led;
    char c,key,f[19]="Created by Bhargav";

    /*initialization */
    TRISB=0; // LCD - data
    TRISC4=0; // LCD - EN
    TRISC5=0; // LCD - RS
    TRISD=0x0F; // KEYPAD - high 4 bit(row) output & low 4 bit(col) input
    TRISA0=0; // MOTOR DRIVER -2
    TRISA1=0; // MOTOR DRIVER -2
    TRISA2=0; // LED-RED
    TRISA3=0; // LED-GREEN
    TRISA4=1; // IR-1
    TRISA5=1; // IR-2

    RA0=0; //Motor off
    RA1=0;

    lcd_init();
    lcd_display('W');
    delay1();
    lcd_display('E');
    delay1();
    lcd_display('L');
    delay1();
    lcd_display('C');
    delay1();
    lcd_display('O');
    delay1();
    lcd_display('M');
    delay1();
    lcd_display('E');
    delay1();


    count =0;

    led=0;
    RA3=0; // Green LED - ON

    here:

    lcd_init();
    display_status(count);

    if(RA4=1) // IR-1
    {
    if(RA5=1)
    {
    count++;

    if (count==count_limit)
    {
    led=1;
    RA3=0;
    RA2=1;
    }

    }

    lcd_init();
    display_status(count);

    goto here;
    }


    if(RA5=1) // IR-2
    {
    if(RA4=1)
    {
    count--;
    if (led==1)
    {
    RA2=0;
    RA3=1;
    led=0;
    }
    }

    lcd_init();
    display_status(count);

    goto here;
    }

    // keypad

    here2:
    key=key_scan(); //call key scan function

    if(key=='f')
    {
    goto here2;
    }

    if(key=='B')
    {
    lcd_command(0x04);
    delay1();
    pass_back(n,pass_c);
    pass_c--;
    goto here2;
    }

    if(key=='E')
    {
    pass_c=0;
    pass_check();
    goto here;
    }

    if(key=='X')
    {
    goto here;
    }

    if(key=='S')
    {
    goto here;
    }

    if(key=='R')
    {
    pass_c=0;
    goto here2;

    }

    if(key=='F')
    {
    lcd_init();
    for (i=0;i<19;i++)
    {
    c=f;
    lcd_display(c);
    delay1();
    }
    }

    else
    {
    if(pass_c==0)
    {
    lcd_init();
    }
    lcd_display('*');
    delay1();
    n=asci_int(key);
    pass(n,pass_c);
    pass_c++;
    goto here2;
    }
    }

    void lcd_init(void)
    {
    lcd_command (0x38);
    delay1();
    lcd_command (0x0E);
    delay1();
    lcd_command (0x01);
    delay1();
    lcd_command (0x06);
    delay1();
    lcd_command (0x84);
    delay1();
    return;
    }

    void lcd_command(int w)
    {
    PORTB=w;
    RC5=0;
    RC4=1;
    delay1();
    RC4=0;
    return;
    }

    void lcd_display(char w)
    {
    PORTB=w;
    RC5=1;
    RC4=1;
    delay1();
    RC4=0;
    return;
    }

    void delay1(void)
    {
    int i,j;

    for (i=0x00;i<=0x32;i++)
    {
    for (j=0x00;j<=0xff;j++)
    {
    }
    }

    return;
    }

    char int_asci(int w)
    {
    char cc;
    switch(w)
    {
    case 0:cc=48;
    break;
    case 1:cc=49;
    break;
    case 2:cc=50;
    break;
    case 3:cc=51;
    break;
    case 4:cc=52;
    break;
    case 5:cc=53;
    break;
    case 6:cc=54;
    break;
    case 7:cc=55;
    break;
    case 8:cc=56;
    break;
    case 9:cc=57;
    break;
    }
    return (cc);
    }

    void display_status(int count)
    {
    int c,c1,c2,c3;
    char cc;

    if (count==count_limit)
    {
    lcd_init();
    display_full();
    }
    else
    {
    lcd_init();
    display_open();
    }

    c= count/10;
    c1=c/10;
    c2=c-(c1*10);
    c3=count-(c*10);


    //display
    lcd_init();
    lcd_display('V');
    delay1();
    lcd_display('E');
    delay1();
    lcd_display('H');
    delay1();
    lcd_display('I');
    delay1();
    lcd_display('C');
    delay1();
    lcd_display('L');
    delay1();
    lcd_display('E');
    delay1();
    lcd_display('S');
    delay1();
    lcd_display('-');
    delay1();
    cc=int_asci(c1);
    lcd_display(cc);
    delay1();
    cc=int_asci(c2);
    lcd_display(cc);
    delay1();
    cc=int_asci(c3);
    lcd_display(cc);
    delay1();

    return;
    }


    char key_scan(void)
    {
    char key_press;

    row1=1;
    row2=0;
    row3=0;
    row4=0;
    if(col1==1)
    {
    key_press=keypad[0][0];
    return(key_press);
    }
    if(col2==1)
    {
    key_press=keypad[0][1];
    return(key_press);
    }
    if(col3==1)
    {
    key_press=keypad[0][2];
    return(key_press);
    }
    if(col4==1)
    {
    key_press=keypad[0][3];
    return(key_press);
    }


    row1=0;
    row2=1;
    row3=0;
    row4=0;
    if(col1==1)
    {
    key_press=keypad[1][0];
    return(key_press);
    }
    if(col2==1)
    {
    key_press=keypad[1][1];
    return(key_press);
    }
    if(col3==1)
    {
    key_press=keypad[1][2];
    return(key_press);
    }
    if(col4==1)
    {
    key_press=keypad[1][3];
    return(key_press);
    }


    row1=0;
    row2=0;
    row3=1;
    row4=0;
    if(col1==1)
    {
    key_press=keypad[2][0];
    return(key_press);
    }
    if(col2==1)
    {
    key_press=keypad[2][1];
    return(key_press);
    }
    if(col3==1)
    {
    key_press=keypad[2][2];
    return(key_press);
    }
    if(col4==1)
    {
    key_press=keypad[2][3];
    return(key_press);
    }


    row1=0;
    row2=0;
    row3=0;
    row4=1;
    if(col1==1)
    {
    key_press=keypad[3][0];
    return(key_press);
    }
    if(col2==1)
    {
    key_press=keypad[3][1];
    return(key_press);
    }
    if(col3==1)
    {
    key_press=keypad[3][2];
    return(key_press);
    }
    if(col4==1)
    {
    key_press=keypad[3][3];
    return(key_press);
    }

    key_press='f';
    return(key_press);
    }

    int asci_int(char w)
    {
    int cc;
    cc=w;
    switch(cc)
    {
    case 48:cc=0;
    break;
    case 49:cc=1;
    break;
    case 50:cc=2;
    break;
    case 51:cc=3;
    break;
    case 52:cc=4;
    break;
    case 53:cc=5;
    break;
    case 54:cc=6;
    break;
    case 55:cc=7;
    break;
    case 56:cc=8;
    break;
    case 57:cc=9;
    break;
    }
    return (cc);
    }

    void pass(int w,int pass_c)
    {
    int temp;
    switch (pass_c)
    {
    case 0: password=w;
    break;
    case 1: temp=w*10;
    password=password+temp;
    break;
    case 2: temp=w*100;
    password=password+temp;
    break;
    case 3: temp=w*1000;
    password=password+temp;
    break;
    }
    return;
    }

    void pass_back(int w,int pass_c)
    {
    int temp;
    switch (pass_c)
    {
    case 0: password=password-w;
    break;
    case 1: temp=w*10;
    password=password-temp;
    break;
    case 2: temp=w*100;
    password=password-temp;
    break;
    case 3: temp=w*1000;
    password=password-temp;
    break;
    }
    return;
    }

    void pass_check(void)
    {
    int i;
    char c,pass_incorrect[52]="Password is Incorrect. Press R to Retry, X to Exit.",pass_correct[23]="Welcome, You may Enter";

    if (password==password1)
    {
    lcd_init();
    for (i=0;i<23;i++)
    {
    c=pass_correct;
    lcd_display(c);
    delay1();
    }
    RA0=1;
    RA1=0;
    motor_delay();
    RA0=0;
    RA1=0;
    car_pass_delay();
    RA0=0;
    RA1=1;
    motor_delay();
    RA0=0;
    RA1=0;
    }
    else
    {
    lcd_init();
    for (i=0;i<52;i++)
    {
    c=pass_incorrect;
    lcd_display(c);
    delay1();
    }
    }
    return;
    }

    void motor_delay(void)
    {
    int i,j;

    for (i=0x00;i<=0xff;i++)
    {
    for (j=0x00;j<=0xff;j++)
    {
    }
    }

    return;
    }

    void display_full(void)
    {
    int i;
    char c,full[23]="Sorry, Parking is Full";

    lcd_init();
    for (i=0;i<23;i++)
    {
    c=full;
    lcd_display(c);
    delay1();
    }
    return;
    }

    void display_open(void)
    {
    int i;
    char c,full[21]="Parking is Available";

    lcd_init();
    for (i=0;i<20;i++)
    {
    c=full;
    lcd_display(c);
    delay1();
    }
    return;
    }

    void car_pass_delay (void)
    {
    int i,j;
    for (i=0x00;i<=0x50;i++)
    {
    for (j=0x00;j<=0xff;j++)
    {
    }
    }
    return;
    }


    ************************************************

    Its a very basic programing so i guess u'll have no problem in figuring out the working .... I have thoroughly checked for errors, but i may have missed some ... And i still think the register bank is the problem, so please let me know how i can shift my code to the nxt bank .... and if u come across any other errors, plz let me know ... thank you
     
  5. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    Code ( (Unknown Language)):
    1. #include<stdio.h>
    2. #include<pic.h>
    3.  
    4. #define col1 RD0
    5. #define col2 RD1
    6. #define col3 RD2
    7. #define col4 RD3
    8. #define row1 RD4
    9. #define row2 RD5
    10. #define row3 RD6
    11. #define row4 RD7
    12.  
    13. #define password1 1234
    14. #define count_limit 10
    15.  
    16. int password,pass_c=0;
    17.  
    18. char keypad[4][4]={    {'1','2','3','4'},
    19.                     {'5','6','7','8'},
    20.                     {'9','0','B','E'},
    21.                     {'X','R','S','F'}  };                            
    22.  
    23. void lcd_command(int w);
    24. void lcd_display(char w);
    25. void lcd_init(void);
    26. void delay1(void);
    27. char int_asci(int w);
    28. int asci_int(char w);              
    29. void display_status(int count);
    30. char key_scan(void);
    31. void pass(int w,int pass_c);
    32. void pass_back(int w,int pass_c);
    33. void pass_check(void);
    34. void motor_delay(void);
    35. void display_full(void);
    36. void display_open(void);
    37. void car_pass_delay(void);
    38.  
    39.                    
    40. void main()
    41. {
    42. int n,count,i,led;
    43. char c,key,f[19]="Created by Bhargav";
    44.  
    45. /*initialization */
    46. TRISB=0;         // LCD - data
    47. TRISC4=0;          // LCD - EN
    48. TRISC5=0;        // LCD - RS
    49. TRISD=0x0F;        // KEYPAD - high 4 bit(row) output & low 4 bit(col)  input
    50. TRISA0=0;      // MOTOR DRIVER -2
    51. TRISA1=0;        // MOTOR DRIVER -2
    52. TRISA2=0;        // LED-RED
    53. TRISA3=0;        // LED-GREEN
    54. TRISA4=1;        // IR-1
    55. TRISA5=1;        // IR-2
    56.  
    57. RA0=0;    //Motor off
    58. RA1=0;
    59.  
    60. lcd_init();
    61. lcd_display('W');
    62. delay1();
    63. lcd_display('E');
    64. delay1();
    65. lcd_display('L');
    66. delay1();
    67. lcd_display('C');
    68. delay1();
    69. lcd_display('O');
    70. delay1();
    71. lcd_display('M');
    72. delay1();
    73. lcd_display('E');
    74. delay1();
    75.  
    76.  
    77. count =0;
    78.  
    79. led=0;
    80. RA3=0;        // Green LED - ON
    81.  
    82. here:
    83.  
    84. lcd_init();
    85. display_status(count);
    86.  
    87. if(RA4=1)                    // IR-1
    88. {
    89.     if(RA5=1)
    90.         {
    91.         count++;
    92.    
    93.         if (count==count_limit)
    94.             {
    95.             led=1;
    96.             RA3=0;
    97.             RA2=1;
    98.             }
    99.  
    100.         }
    101.    
    102. lcd_init();
    103. display_status(count);
    104.  
    105. goto here;
    106. }
    107.  
    108.  
    109. if(RA5=1)                    // IR-2
    110. {
    111.     if(RA4=1)
    112.         {
    113.         count--;
    114.             if (led==1)
    115.             {
    116.             RA2=0;
    117.             RA3=1;
    118.             led=0;
    119.             }
    120.         }
    121.    
    122. lcd_init();
    123. display_status(count);
    124.  
    125. goto here;
    126. }
    127.  
    128. // keypad
    129.  
    130. here2:    
    131.     key=key_scan();    //call key scan function
    132.    
    133.     if(key=='f')
    134.     {
    135.     goto here2;
    136.     }
    137.    
    138.     if(key=='B')
    139.     {
    140.     lcd_command(0x04);
    141.     delay1();
    142.     pass_back(n,pass_c);
    143.     pass_c--;
    144.     goto here2;
    145.     }
    146.  
    147.     if(key=='E')
    148.     {
    149.     pass_c=0;
    150.     pass_check();
    151.     goto here;
    152.     }
    153.  
    154.     if(key=='X')
    155.     {
    156.     goto here;
    157.     }
    158.    
    159.     if(key=='S')
    160.     {
    161.     goto here;
    162.     }
    163.  
    164.     if(key=='R')
    165.     {
    166.     pass_c=0;
    167.     goto here2;
    168.  
    169.     }
    170.    
    171.     if(key=='F')
    172.     {
    173.     lcd_init();
    174.     for (i=0;i<19;i++)
    175.         {
    176.         c=f[i];
    177.         lcd_display(c);
    178.         delay1();
    179.         }
    180.     }
    181.  
    182.     else
    183.     {
    184.     if(pass_c==0)
    185.     {
    186.     lcd_init();
    187.     }
    188.     lcd_display('*');
    189.     delay1();
    190.     n=asci_int(key);
    191.     pass(n,pass_c);
    192.     pass_c++;
    193.     goto here2;
    194.     }
    195. }
    196.  
    197. void lcd_init(void)
    198. {
    199. lcd_command (0x38);
    200. delay1();
    201. lcd_command (0x0E);
    202. delay1();
    203. lcd_command (0x01);
    204. delay1();
    205. lcd_command (0x06);
    206. delay1();
    207. lcd_command (0x84);
    208. delay1();
    209. return;
    210. }
    211.  
    212. void lcd_command(int w)
    213. {
    214. PORTB=w;
    215. RC5=0;
    216. RC4=1;
    217. delay1();
    218. RC4=0;
    219. return;
    220. }
    221.  
    222. void lcd_display(char w)
    223. {
    224. PORTB=w;
    225. RC5=1;
    226. RC4=1;
    227. delay1();
    228. RC4=0;
    229. return;
    230. }
    231.  
    232. void delay1(void)
    233. {
    234. int i,j;
    235.  
    236. for (i=0x00;i<=0x32;i++)
    237.     {
    238.         for (j=0x00;j<=0xff;j++)
    239.             {
    240.             }
    241.     }
    242.  
    243. return;
    244. }
    245.  
    246. char int_asci(int w)
    247. {
    248. char cc;
    249. switch(w)
    250. {
    251. case 0:cc=48;
    252.             break;
    253. case 1:cc=49;
    254.             break;
    255. case 2:cc=50;
    256.             break;
    257. case 3:cc=51;
    258.             break;
    259. case 4:cc=52;
    260.             break;
    261. case 5:cc=53;
    262.             break;
    263. case 6:cc=54;
    264.             break;
    265. case 7:cc=55;
    266.             break;
    267. case 8:cc=56;
    268.             break;
    269. case 9:cc=57;
    270.             break;
    271. }
    272. return (cc);
    273. }
    274.  
    275. void display_status(int count)
    276. {
    277. int c,c1,c2,c3;
    278. char cc;
    279.  
    280. if (count==count_limit)
    281. {
    282. lcd_init();
    283. display_full();
    284. }
    285. else
    286. {
    287. lcd_init();
    288. display_open();
    289. }
    290.  
    291. c= count/10;
    292. c1=c/10;
    293. c2=c-(c1*10);
    294. c3=count-(c*10);
    295.  
    296.  
    297. //display
    298. lcd_init();
    299. lcd_display('V');
    300. delay1();
    301. lcd_display('E');
    302. delay1();
    303. lcd_display('H');
    304. delay1();
    305. lcd_display('I');
    306. delay1();
    307. lcd_display('C');
    308. delay1();
    309. lcd_display('L');
    310. delay1();
    311. lcd_display('E');
    312. delay1();
    313. lcd_display('S');
    314. delay1();
    315. lcd_display('-');
    316. delay1();
    317. cc=int_asci(c1);
    318. lcd_display(cc);
    319. delay1();
    320. cc=int_asci(c2);
    321. lcd_display(cc);
    322. delay1();
    323. cc=int_asci(c3);
    324. lcd_display(cc);
    325. delay1();
    326.  
    327. return;
    328. }
    329.  
    330.  
    331. char key_scan(void)
    332. {
    333.     char key_press;
    334.    
    335.     row1=1;
    336.     row2=0;
    337.     row3=0;
    338.     row4=0;
    339.     if(col1==1)
    340.     {
    341.     key_press=keypad[0][0];
    342.     return(key_press);
    343.     }
    344.     if(col2==1)
    345.     {
    346.     key_press=keypad[0][1];
    347.     return(key_press);
    348.     }
    349.     if(col3==1)
    350.     {
    351.     key_press=keypad[0][2];
    352.     return(key_press);
    353.     }
    354.     if(col4==1)
    355.     {
    356.     key_press=keypad[0][3];
    357.     return(key_press);
    358.     }
    359.  
    360.  
    361.     row1=0;
    362.     row2=1;
    363.     row3=0;
    364.     row4=0;
    365.     if(col1==1)
    366.     {
    367.     key_press=keypad[1][0];
    368.     return(key_press);
    369.     }
    370.     if(col2==1)
    371.     {
    372.     key_press=keypad[1][1];
    373.     return(key_press);
    374.     }
    375.     if(col3==1)
    376.     {
    377.     key_press=keypad[1][2];
    378.     return(key_press);
    379.     }
    380.     if(col4==1)
    381.     {
    382.     key_press=keypad[1][3];
    383.     return(key_press);
    384.     }
    385.  
    386.  
    387.     row1=0;
    388.     row2=0;
    389.     row3=1;
    390.     row4=0;
    391.     if(col1==1)
    392.     {
    393.     key_press=keypad[2][0];
    394.     return(key_press);
    395.     }
    396.     if(col2==1)
    397.     {
    398.     key_press=keypad[2][1];
    399.     return(key_press);
    400.     }
    401.     if(col3==1)
    402.     {
    403.     key_press=keypad[2][2];
    404.     return(key_press);
    405.     }
    406.     if(col4==1)
    407.     {
    408.     key_press=keypad[2][3];
    409.     return(key_press);
    410.     }
    411.  
    412.  
    413.     row1=0;
    414.     row2=0;
    415.     row3=0;
    416.     row4=1;
    417.     if(col1==1)
    418.     {
    419.     key_press=keypad[3][0];
    420.     return(key_press);
    421.     }
    422.     if(col2==1)
    423.     {
    424.     key_press=keypad[3][1];
    425.     return(key_press);
    426.     }
    427.     if(col3==1)
    428.     {
    429.     key_press=keypad[3][2];
    430.     return(key_press);
    431.     }
    432.     if(col4==1)
    433.     {
    434.     key_press=keypad[3][3];
    435.     return(key_press);
    436.     }
    437.  
    438.     key_press='f';
    439.     return(key_press);
    440. }
    441.  
    442. int asci_int(char w)
    443. {
    444. int cc;
    445. cc=w;
    446. switch(cc)
    447. {
    448. case 48:cc=0;
    449.             break;
    450. case 49:cc=1;
    451.             break;
    452. case 50:cc=2;
    453.             break;
    454. case 51:cc=3;
    455.             break;
    456. case 52:cc=4;
    457.             break;
    458. case 53:cc=5;
    459.             break;
    460. case 54:cc=6;
    461.             break;
    462. case 55:cc=7;
    463.             break;
    464. case 56:cc=8;
    465.             break;
    466. case 57:cc=9;
    467.             break;
    468. }
    469. return (cc);
    470. }
    471.  
    472. void pass(int w,int pass_c)
    473. {
    474. int temp;
    475. switch (pass_c)
    476. {
    477. case 0:    password=w;
    478.         break;
    479. case 1:    temp=w*10;
    480.         password=password+temp;
    481.         break;
    482. case 2:    temp=w*100;
    483.         password=password+temp;
    484.         break;
    485. case 3:    temp=w*1000;
    486.         password=password+temp;
    487.         break;
    488. }
    489. return;
    490. }
    491.  
    492. void pass_back(int w,int pass_c)
    493. {
    494. int temp;
    495. switch (pass_c)
    496. {
    497. case 0:    password=password-w;
    498.         break;
    499. case 1:    temp=w*10;
    500.         password=password-temp;
    501.         break;
    502. case 2:    temp=w*100;
    503.         password=password-temp;
    504.         break;
    505. case 3:    temp=w*1000;
    506.         password=password-temp;
    507.         break;
    508. }
    509. return;
    510. }
    511.  
    512. void pass_check(void)
    513. {
    514. int i;
    515. char c,pass_incorrect[52]="Password is Incorrect. Press R to Retry, X to  Exit.",pass_correct[23]="Welcome, You may Enter";
    516.  
    517. if (password==password1)
    518. {
    519. lcd_init();
    520.     for (i=0;i<23;i++)
    521.         {
    522.         c=pass_correct[i];
    523.         lcd_display(c);
    524.         delay1();
    525.         }
    526. RA0=1;
    527. RA1=0;
    528. motor_delay();
    529. RA0=0;
    530. RA1=0;
    531. car_pass_delay();
    532. RA0=0;
    533. RA1=1;
    534. motor_delay();
    535. RA0=0;
    536. RA1=0;
    537. }
    538. else
    539. {
    540. lcd_init();
    541.     for (i=0;i<52;i++)
    542.         {
    543.         c=pass_incorrect[i];
    544.         lcd_display(c);
    545.         delay1();
    546.         }
    547. }
    548. return;
    549. }
    550.  
    551. void motor_delay(void)
    552. {
    553. int i,j;
    554.  
    555. for (i=0x00;i<=0xff;i++)
    556.     {
    557.         for (j=0x00;j<=0xff;j++)
    558.             {
    559.             }
    560.     }
    561.  
    562. return;
    563. }
    564.  
    565. void display_full(void)
    566. {
    567. int i;
    568. char c,full[23]="Sorry, Parking is Full";
    569.  
    570. lcd_init();
    571.     for (i=0;i<23;i++)
    572.         {
    573.         c=full[i];
    574.         lcd_display(c);
    575.         delay1();
    576.         }
    577. return;
    578. }
    579.  
    580. void display_open(void)
    581. {
    582. int i;
    583. char c,full[21]="Parking is Available";
    584.  
    585. lcd_init();
    586.     for (i=0;i<20;i++)
    587.         {
    588.         c=full[i];
    589.         lcd_display(c);
    590.         delay1();
    591.         }
    592. return;
    593. }
    594.  
    595. void car_pass_delay (void)
    596. {
    597. int i,j;
    598. for (i=0x00;i<=0x50;i++)
    599.     {
    600.         for (j=0x00;j<=0xff;j++)
    601.             {
    602.             }
    603.     }
    604. return;
    605. }[/i][/i][/i][/i][/i]
    Should have used the code tags to make it more readable.... What C compiler where you using with MPLAB??
     
    Last edited: Apr 15, 2010
  6. bhargav_17789

    Thread Starter New Member

    Apr 15, 2010
    3
    0
    sorry, i am new to this ... so didn know much about code tags

    I am using Hi-Tech PICC Lite v8.05
     
  7. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    Your program is not at all easy to read. In fact to be brutally honest your program is a mess. No comments,too much code cramped into the "main" function and any structure the program might have had has been destroyed by "goto" statements.

    Rule 1 of C programming. Never Ever Ever use a "goto" statement! Ok, there may be the very rare occasion where a goto statement is legitimate but in more than 10 years of programming PICs in C I have not struck one.
    If you are forced to use a goto its a sure indication that you need to add an extra function.

    Rule 2 of C programming. Don't be afraid to add extra functions. Functions are what give the C language structure so within the bounds of common-sense the more functions the better. For example your main() function is cluttered up with various initialisation statements (port configs, lcd configs etc), all of these could be put into a separate function init() that would be called from main()


    This is not a full list of what is wrong as I have just skimmed through your code;

    No config statement for setting the PIC config bits; clock mode, watchdog timer etc.
    No _XTAL_FREQ statement to tell the assembler your clock frequency.
    Several instances of "if(this = that){... whereas what you meant was if(this == that){...
    lcd_init() called several times and in more than one location. lcd_init() only needs to be called once at the start of the program


    Why do you think its a bank problem?
    I think its a linker problem!
    Did you specify a valid linker script when you did the manual assembly?
    Without a linker script telling it the memory layout of your chip the linker will not know where to locate various parts of your code. This ties in with the errors you are seeing.
    Save yourself a lot of hassle and get the assembler working through MPLAB. That way as long as you tell MPLAB your chip type it will automatically tell the assembler/linker which headers and scripts it needs to use.

    I would start by putting your current project on hold for a short time and write a simple program to light a led. Get it to assemble and run. This will prove your MPLAB/HiTechC setup. Once it works you can come back to your project.
     
Loading...