microcontroller - Digital Clock C code / PIC, Protues -


i'm taking microcontroller course semester, , have assignment make digital clock using pic18 , display on lcd. code in c , i'm protues simulate.

i wrote code wrong if can me figure out mistake.. thank you

    #include <p18f4580.h>  #define ldata portd #define rs portbbits.rb0 #define rw portbbits.rb1 #define en portbbits.rb2   void msdelay(unsigned int itime) {   unsigned int i,j;     (i=0; i<itime; i++)         (j=0; j<135; j++); }  void lcdcmd(unsigned char value) {   ldata = value;     rs = 0;     rw = 0;     en = 1;     msdelay(1);     en = 0; }  void lcddata(unsigned char value) {   ldata = value;     rs = 1;     rw = 0;     en = 1;     msdelay(1);     en = 0; }  void main() {     trisd = 0;     trisb = 0;     en = 0;      int mscounter  =0;     int seccounter =0;     int mincounter =0;     int hrcounter  =0;      msdelay(15);     lcdcmd(0x01);   //clear display     msdelay(15);     lcdcmd(0x02);   //home cursor     msdelay(15);     lcdcmd(0x06);   //left right, still     msdelay(250);     lcdcmd(0x0e);   //display cursor     msdelay(250);     lcdcmd(0x3c);   //5x10 2 lines     msdelay(15);     lcdcmd(0x86);        while(1)     {     msdelay(15);     lcdcmd(0x08);     lcddata(seccounter);          msdelay(15);         mscounter++;          if (mscounter==1000)         {seccounter++;      mscounter=0;    }         if (seccounter==60)         {mincounter++;      seccounter=0;   }         if (mincounter==60)         {hrcounter++;       mincounter=0;   }         if (hrcounter==24)         {hrcounter=0;                       }          msdelay(15);         lcddata(hrcounter);         msdelay(15);         lcddata(':');         msdelay(15);         lcddata(mincounter);         msdelay(15);         lcddata(':');         msdelay(15);         lcddata(seccounter);     } } 

its better display digital clock using 7-segment display in lcd.


Comments