CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

74hc595 4 Digit 38mm C Driver !

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yakuzaistanbul



Joined: 04 Jan 2010
Posts: 2

View user's profile Send private message

74hc595 4 Digit 38mm C Driver !
PostPosted: Mon Jan 04, 2010 2:23 pm     Reply with quote

74hc595 4 Digit 38mm C Driver !

74hc595 serial connect C code please

Digital clock.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 2:46 pm     Reply with quote

Quote:
74hc595 serial connect C code please

Do you think we are your code slaves, to produce code on demand ?
We are all volunteers, working in industry or elsewhere. We like
to answer questions, but not to be code slaves.
yakuzaistanbul



Joined: 04 Jan 2010
Posts: 2

View user's profile Send private message

PostPosted: Mon Jan 04, 2010 3:20 pm     Reply with quote

sorry

I want students to develop amateur lcd temperature display with clock and I did. I wanted to get help with segment I wanted to. lcd with the code
Code:

#include "16f628a.h"                //Mikrodenetleyici seçilir
#fuses    INTRC_IO, NOWDT, PROTECT, PUT, NOMCLR        //Sigortalar seçilir

#use    delay (clock=4000000)                  //Osilatör hızı belirlenir

#use    rs232(baud =4800, PARITY=N, xmit=PIN_A2, rcv=PIN_A1, BITS =8, ERRORS, STOP=2, STREAM = PORT1)
#use    I2C(master, slow, RESTART_WDT, sda=PIN_A7, scl=PIN_A6)
                   

                     

#define    LCD_EN            PIN_B0
#define    LCD_RS             PIN_B1
#define    LCD_RW             PIN_B2
                                                     
#define    LCD_D4                PIN_B4
#define    LCD_D5                PIN_B5
#define    LCD_D6                PIN_B6
#define    LCD_D7                PIN_B7

#define    LINE_1                  0x00
#define    LINE_2                  0x40
#define    LCD_CLR_DISP          0X01 // Clear screen, home cursor, unshift display
#define    LCD_RETURN_HOME       0X02 // Home cursor, unshift display
#define    LCD_ENTRY_DEC          0X04 // Display shift off, dec cursor move dir
#define    LCD_ENTRY_DEC_SHIFT       0x05 // Display shift on, dec cursor move dir
#define    LCD_ENTRY_INC          0x06 // Display shift off, inc cursor move dir
#define    LCD_ENTRY_INC_SHIFT       0x07 // Display shift on, inc cursor move dir
#define    LCD_DISP_OFF          0x08 // Display off
#define    LCD_DISP_ON          0x0C // Display on, cursor off
#define    LCD_DISP_ON_BLINK       0x0D // Display on, cursor off, blink char
#define    LCD_DISP_ON_CURSOR       0x0E // Display on, cursor on
#define    LCD_DISP_ON_CURSOR_BLINK   0x0F // Display on, cursor on, blink char
#define    LCD_MOVE_CURSOR_LEFT       0x10 // Move cursor left (decrement)
#define    LCD_MOVE_CURSOR_RIGHT       0x14 // Move cursor right (increment)
#define    LCD_MOVE_DISP_LEFT       0x18 // Shift display left
#define    LCD_MOVE_DISP_RIGHT       0x1C // Shift display right
#define    LCD_FUNCTION_4BIT_1LINE      0x20 // 4-bit interface, single line, 5x7 dots
#define    LCD_FUNCTION_4BIT_2LINES   0x28 // 4-bit interface, dual line, 5x7 dots
#define    LCD_FUNCTION_8BIT_1LINE    0x30 // 8-bit interface, single line, 5x7 dots
#define    LCD_FUNCTION_8BIT_2LINES    0x38 // 8-bit interface, dual line, 5x7 dots
#define    LCD_CGRAM_BASE_ADDR       0x40 // Set the CGRAM address
#define    LCD_DDRAM_BASE_ADDR       0x80 // Set the DDRAM address
#define    LCD_LINE_1          0x80 // Position of start of line 1
#define    LCD_LINE_2          0xC0 // Position of start of line 2
#define    LCD_LINE_3          0x94 // Position of start of line 3
#define    LCD_LINE_4          0xD4 // Position of start of line 4
#define    LCD_DEGREE_CHAR       0x00 // Ascii 00
#define    LCD_TYPE          2 // 0=5x7, 1=5x10, 2=2 lines
               
                                             

void   Ds1307Init(void);
void   OkuDs1307(void);
void   InitTmp100(void);
void   OkuTmp100(void);
 

void      LCD_Init(void);
void      LCD_SetPosition(unsigned int);
void      LCD_PutChar(unsigned int);
void      LCD_PutCmd(Unsigned int);
void      LCD_PulseEnable(void);
void      LCDInit_PulseEnable(void);
void      LCD_SetData(unsigned int);
 


int   SicaklikTmp100Isaret=' ', SicaklikTmp100Basamak1, SicaklikTmp100Basamak2, SicaklikTmp100Basamak3;
int   SicaklikDegeri;
int   SayacRunLed1, SayacRunLed2;
int    Saniye, Dakika, Saat, HaftaGun, Aygun, Ay, Yil;
int   SaniyeAlt, SaniyeUst, DakikaAlt, DakikaUst, SaatAlt, SaatUst, HaftaGunAlt, HaftaGunUst;
int   AygunAlt, AygunUst, AyAlt, AyUst, YilAlt, YilUst;
int   BufferSaniye, SayacIkiNokta;



//#int_RTCC
//void   Timer9KesmeGeldi(void){
                                 
 //  if(SayacRunLed1==0){
   
 //     OkuDs1307();
 //     OkuTmp100();
 //  }   

 //  restart_wdt();
//}                                                               


 

void   LCD_SetPosition(unsigned int cX){
   LCD_SetData(swap(cX) | 0x08 );
   LCD_PulseEnable();
   LCD_SetData(swap(cX) );
   LCD_PulseEnable();
}




void   LCD_SetData(unsigned int cX){
   output_bit(LCD_D4, cX & 0x01);
   output_bit(LCD_D5, cX & 0x02);
   output_bit(LCD_D6, cX & 0x04);
   output_bit(LCD_D7, cX & 0x08);
}

                                         
                                                   

void   LCD_PulseEnable(void){
   output_high(LCD_EN);
   delay_us(10);
   output_low(LCD_EN);           
   delay_ms(20);
}                 



                 
void   LCDInit_PulseEnable(void){
   output_high(LCD_EN);
   delay_us(10);
   output_low(LCD_EN);
   delay_ms(20);
}




void   LCD_PutCmd(unsigned int cX){
   LCD_SetData(swap (cX) );     /* send high nibble */
   LCD_PulseEnable();
   LCD_SetData(swap(cX) );     /* send low nibble */
   LCD_PulseEnable();
}




void   LCD_PutChar(unsigned int cX ){
          output_high(LCD_RS);
        LCD_SetData(swap(cX));     /* send high nibble */
   LCD_PulseEnable();
        LCD_SetData(swap(cX));     /* send low nibble */
        LCD_PulseEnable();
        output_low(LCD_RS);
}


                                     
                   
void    LCDInit(void){
   LCD_SetData(0X00); 
   delay_ms(400);       /* wait enough time after Vdd rise */
   output_low(LCD_RS);
   LCD_SetData(0X03);   /* init with specific nibbles to start 4-bit mode */
   LCDInit_PulseEnable();
   LCDInit_PulseEnable();
   LCDInit_PulseEnable();
   LCD_SetData(0x02);   /* set 4-bit interface */
   LCDInit_PulseEnable();      /* send dual nibbles hereafter, MSN first */
   LCD_PutCmd(0x2C);    /* function set (all lines, 5x7 characters) */
   LCD_PutCmd(0x0C);    /* display ON, cursor off, no blink */
   LCD_PutCmd(0x01);    /* clear display */
   LCD_PutCmd(0x06);    /* entry mode set, increment & scroll left */
}



void    OkuDs1307(void){
   i2c_stop();
   i2c_stop();
   i2c_start();
   i2c_write(0xD0);
   i2c_write(0x00);

   i2c_start();
   i2c_write(0xD1);

   Saniye   =i2c_read(1);
   Dakika   =i2c_read(1);
   Saat   =i2c_read(1);
   HaftaGun=i2c_read(1);
   AyGun   =i2c_read(1);
   Ay   =i2c_read(1);
   Yil   =i2c_read(0);
   i2c_stop();

   SaniyeAlt=(Saniye&0X0F)      ;
   SaniyeUst=((Saniye>>4)&0X07)   ;
   DakikaAlt=(Dakika&0X0F)      ;
   DakikaUst=((Dakika>>4)&0X07)   ;
   SaatAlt  =(Saat&0X0F)      ;
   SaatUst  =((Saat>>4)&0X07)   ;
   AyGunAlt =(AyGun&0X0F)      ;
   AyGunUst =((AyGun>>4)&0X07)   ;
   AyAlt    =(Ay&0X0F)      ;
   AyUst     =((Ay>>4)&0X07)   ;
   YilAlt   =(Yil&0X0F)      ;
   YilUst   =((Yil>>4)&0X07)   ;

   if(Saniye != BufferSaniye){
      SayacIkiNokta=250;
      BufferSaniye=Saniye;
   }
}






void Ds1307Init(void){                   //Start biti ve konfigürasyon Çalışıyor
   int   Durum;
   i2c_stop();
   i2c_stop();

   i2c_start();
   i2c_write(0xD0);
   i2c_write(0x00);

   i2c_start();
   i2c_write(0xD1);
   Durum = i2c_read(0);
   i2c_stop();

   Durum &= 0x7F;

   i2c_start();
   i2c_write(0xD0);
   i2c_write(0x00);
   i2c_write(Durum);

   i2c_start();
   i2c_write(0xD0);
   i2c_write(0x07);
   i2c_write(0x92);
   i2c_stop();

   i2c_start();
   i2c_write(0xD1);
   Durum = i2c_read(0);
   i2c_stop();
}




                                                 
void   OkuTmp100(void){
   int      DegerAlt, DegerUst, Temp;

   i2c_stop();
   i2c_stop();

   i2c_start();
   i2c_write(0X90);
   i2c_write(0X00);

   i2c_start();
   i2c_write(0X91);
   DegerUst = i2c_read(1);
   DegerAlt = swap(i2c_read(0));
   i2c_stop();

   if(bit_test(DegerAlt, 7) == 1){
      SicaklikTmp100Isaret = ' ';

      i2c_stop();
      i2c_stop();
      i2c_start();
      i2c_write(0X90);
      i2c_write(0X01);
      i2c_write(0X60);
       
      i2c_stop();
   }
   else{
      if(bit_test(DegerUst, 7) == 0){
         SicaklikTmp100Isaret = '+';

         if(DegerUst<100){
            SicaklikTmp100Basamak3 = 0;
            SicaklikTmp100Basamak2 = DegerUst/10;
            SicaklikTmp100Basamak1 = DegerUst%10;
         }
         else{
            SicaklikTmp100Basamak3 = 1;       
            SicaklikTmp100Basamak2 = (DegerUst-100)/10;
            SicaklikTmp100Basamak1 = DegerUst%10;
         }     
      }

      else{
         SicaklikTmp100Isaret = '-';
         bit_clear(DegerUst, 7);
         Temp = 127-DegerUst;

         SicaklikTmp100Basamak3 = 0;
         SicaklikTmp100Basamak2 = DegerUst/10;
         SicaklikTmp100Basamak1 = DegerUst%10;
      }
     
      SicaklikDegeri=   SicaklikTmp100Basamak3*100+SicaklikTmp100Basamak2*10+SicaklikTmp100Basamak1-1;
   }
}         




void main (void){                       
   set_tris_a(0Xff);    // a port giriş giriş olarak yönlendiriliyor
   set_tris_b(0X00);    // b port çıkış
   LcdInit();                       
        Ds1307Init();                     
 //  fprintf(PORT1,"Start",); 
                       
   LCD_SetPosition (LINE_1 + 0);
   printf (LCD_PutChar, "    Fatih    ");
   LCD_SetPosition (LINE_2 + 0);
   printf (LCD_PutChar, " Ortam Sicakligi  ");
   delay_ms(1000);                     
   
//      enable_interrupts(INT_RTCC);               
 // enable_interrupts  (GLOBAL);       
                                                                 
   while(true){

     
         OkuTmp100();
         OkuDs1307();
     
  //      fprintf(PORT1,"%d  - \x0D\X0A ", SicaklikDegeri);
                                           
         LCD_SetPosition (LINE_1 + 0);
         printf(LCD_PutChar,"%c %d %d%d: %d%d: %d%d ", SicaklikTmp100Isaret, SicaklikDegeri,
        SaatUst,SaatAlt, DakikaUst,DakikaAlt, SaniyeUst,SaniyeAlt,);
         delay_ms(50);
         

               
          if(input(PIN_A5)==1){
 
         if(++DakikaAlt>9){
          DakikaAlt=0;
         if(++DakikaUst>5){
         DakikaUst=0;     }
                           }
         Dakika = ((DakikaUst<<4) | DakikaAlt);
         I2C_Start();
         I2C_Write(0xD0);
         I2C_Write(0x01);
         I2C_Write(Dakika);
         I2C_Stop();     
               
               
   }
}
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group