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

problem with sequence running [solved]

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



Joined: 14 May 2012
Posts: 3

View user's profile Send private message

problem with sequence running [solved]
PostPosted: Mon May 14, 2012 7:07 pm     Reply with quote

I am having a problem getting this code to work to run the sequence as I have it loading. I am trying to flash 8 leds on port b of a pic16f628. I have had it working other ways but wanted to make the c code smaller.
Code:

#include <16F628A.h>

#fuses INTRC_IO,NOPROTECT,NOWDT,PUT,NOMCLR

#use delay(clock=4000000)
#use standard_io(b)

#byte port_b = 6

char rom led_tab[] =  {0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0x00,
                               0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,
                               0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,
                               0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,
                               0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,
                               0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
                               0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
                               0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
                               0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,
                               0x7E,0xFF,0x7E,0xFF,0x7E,0xFF,0x7E,0xFF,
                               0xBD,0xFF,0xBD,0xFF,0xBD,0xFF,0xBD,0xFF,
                               0xDB,0xFF,0xDB,0xFF,0xDB,0xFF,0xDB,0xFF,
                               0xE7,0xFF,0xE7,0xFF,0xE7,0xFF,0xE7,0xFF,
                               0xE7,0xFF,0xE7,0xFF,0xE7,0xFF,0xE7,0xFF,
                               0xDB,0xFF,0xDB,0xFF,0xDB,0xFF,0xDB,0xFF,
                               0xBD,0xFF,0xBD,0xFF,0xBD,0xFF,0xBD,0xFF,
                               0x7E,0xFF,0x7E,0xFF,0x7E,0xFF,0x7E,0xFF};
                               
void  main(void)
{
set_TRIS_B(0x00); /* set port_b to be outputs */
PORTB = 0; /* initialize All port_b outputs to be zero */
     
while( TRUE )
  {
   /* forever loop using WHILE construct */
   char i;
   for(i=0; i<136; i++)
   {
      PORTB = led_tab[i];
      delay_ms(100);
   }
  }
}


when i run the above code in proteus all it does is all 8 leds light up and stay lit .and when i wrote it to the pic and tested it it does the same in hardware as well.
jrugar



Joined: 14 May 2012
Posts: 3

View user's profile Send private message

PostPosted: Mon May 14, 2012 7:19 pm     Reply with quote

Got it fixed after posting changed from char rom to char const and fixed my portb it should be port_b issue in the main code.
jrugar



Joined: 14 May 2012
Posts: 3

View user's profile Send private message

New Version of Code
PostPosted: Tue May 15, 2012 1:24 am     Reply with quote

Use this code to help learn and make better things from it i am giving this version to the public to have fun with and learn.

Code:

/******************************************************************************
 * (c)2012 Joe Rugar                                                          *
 * Pic16f628a LED sequence flasher v1.0                                       *
 *                                                                            *
 *   This program is free software: you can redistribute it and/or modify     *
 *   it under the terms of the GNU General Public License as published by     *
 *   the Free Software Foundation, either version 3 of the License, or        *
 *   (at your option) any later version.                                      *
 *                                                                            *
 *   This program is distributed in the hope that it will be useful,          *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of           *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
 *   GNU General Public License for more details.                             *
 *                                                                            *
 *   You should have received a copy of the GNU General Public License        *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
 ******************************************************************************/
 
#include <16F628A.h>

#fuses INTRC_IO,NOPROTECT,NOWDT,PUT,NOMCLR

#use delay(clock=4000000)
#use standard_io(b)

#byte port_b = 6

char const led_tab[] =  {0b00000000,0b11111111,0b00000000,0b11111111,0b00000000,0b11111111,0b00000000,0b11111111,
                         0b00000001,0b00000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000,
                         0b00000001,0b00000010,0b00000100,0b00001000,0b00010000,0b00100000,0b01000000,0b10000000,
                         0b10000000,0b01000000,0b00100000,0b00010000,0b00001000,0b00000100,0b00000010,0b00000001,
                         0b10000000,0b01000000,0b00100000,0b00010000,0b00001000,0b00000100,0b00000010,0b00000001,
                         0b10000001,0b11000011,0b11100111,0b11111111,0b11111111,0b11100111,0b11000011,0b10000001,
                         0b00011000,0b00111100,0b01111110,0b11111111,0b11111111,0b01111110,0b00111100,0b00011000,
                         0b10011001,0b01100110,0b10011001,0b01100110,0b10011001,0b01100110,0b10011001,0b01100110,
                         0b11001100,0b00110011,0b11001100,0b00110011,0b00110011,0b11001100,0b00110011,0b11001100,
                         0b11001100,0b00110011,0b11001100,0b00110011,0b00110011,0b11001100,0b00110011,0b11001100,
                         0b11000011,0b00111100,0b00111100,0b11000011,0b00111100,0b11000011,0b11000011,0b00111100,
                         0b11000011,0b00111100,0b00111100,0b11000011,0b00111100,0b11000011,0b11000011,0b00111100};
 
void seq1(void);
void seq2(void);
void seq3(void);
void seq4(void);
void seq5(void);

void  main(void)
{

   
   
      set_TRIS_B(0x00); /* set port_b to be outputs */
      port_b = 0; /* initialize All port_b outputs to be zero */
     
      while( TRUE )
       {
       /* forever loop using WHILE construct */
        seq1();
        delay_ms(1000);
        seq2();
        delay_ms(1000);
        seq3();
        delay_ms(1000);
        seq4();
        delay_ms(1000);
        seq5();
       }
}

void seq1(void)
{
   char i;
   for(i=0; i<96; i++)
   {
      port_b = led_tab[i];
      delay_ms(50);
   }
}

void seq2(void)
{
   char i;
   for(i=0; i<96; i++)
   {
      port_b = led_tab[i];
      delay_ms(100);
   }
}

void seq3(void)
{
   char i;
   for(i=0; i<96; i++)
   {
      port_b = led_tab[i];
      delay_ms(70);
   }
}

void seq4(void)
{
char i;
   for(i=0; i<96; i++)
   {
      port_b = led_tab[i];
      delay_ms(80);
   }
}

void seq5(void)
{
   char i;
   for(i=0; i<96; i++)
   {
      port_b = led_tab[i];
      delay_ms(30);
   }
}
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue May 15, 2012 5:40 am     Reply with quote

Thanks Joe! I am sure it will be beneficial to some of the folks here and
future visitors. Maybe a copy could be put in the Code Library?
_________________
Google and Forum Search are some of your best tools!!!!
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