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 support@ccsinfo.com

7 segment driver chip

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



Joined: 24 Jun 2005
Posts: 206

View user's profile Send private message Send e-mail

7 segment driver chip
PostPosted: Mon Aug 24, 2009 10:26 pm     Reply with quote

Hi All, Doing a project with a stack of 7 segments, I have decided to make my own driver chip, cheaper the buying the maxim parts.

Here is my code;

Code:

#include <18F4680.h>
#fuses EC_IO,NOWDT,NOPROTECT,NOLVP,NODEBUG,NOMCLR
#use delay(clock=4000000)

#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0xa0)

const char digit[10]={
//0   1     2     3     4     5     6     7     8     9
0xC0, 0xF9, 0xA4, 0xB0, 0x99, 0x92, 0x82, 0xF8, 0x80, 0x90
};

int display_string[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8};      //this is the last 4 digets of both displays, leading zero is not used

int index = 1;
int out_port = 0b11111110;

#INT_SSP
void i2c_isr()
   {   
      int state, incoming, address;
      state = i2c_isr_state();
   
      if(state < 0x80)                           //Master is sending data
         {
            incoming = i2c_read();
            if(state == 0)                        //First received byte is address
               address = incoming;
            if(state == 1)                        //Second received byte is data
               display_string[address] = incoming;
         }
   }

#int_rtcc                         
void clock_isr()
   {
//      delay_ms(500);                              //test delay only
      output_b(0xFF);
      output_d(digit[display_string[index]]);
      output_b(out_port);
      delay_ms(1);

      if(index >= 8)
         {
            index = 1;
            out_port = 0b11111110;
         }

      else
         {
            index++;
            rotate_left(&out_port,1);            
         }
   }

void main(void)
   {
      output_b(0xFF);
      output_d(0xFF);   

      setup_counters(RTCC_INTERNAL, RTCC_DIV_16 | RTCC_8_BIT);
        enable_interrupts(INT_RTCC);
        enable_interrupts(INT_SSP);
        enable_interrupts(GLOBAL);   

      while(1)
         {
            delay_us(1);            
         }
   }


It works, at least in simulation, but I was just wondering if there is anything i could\should improve or change.

Thanks

mark
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