Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

using a RTC in SF basic

MrDEB

Well-Known Member
I have a DS-1302 RTC module but how to use it?
I recall Jon Chandler made a vu meter clock but what he used for timing?
Am planning on a clock that has no hands, just LEDs but precision would be nice.
 
and separate data lines for the different colored Leds

I am sorry to be harsh, but you have more resistance to actually LEARNING AND UNDERSTANDING something than anybody I know.

The concept was fully explained in post #192 and others.

To update the LEDs, one byte is shifted out for EVERY 74595 in the string, EVERY TIME. This isn't complicated. Set up an array of bytes equal to the number of 74595s. If you set each byte to zero, all the LEDs will be off. If you set each byte to 255 (i.e., %11111111), all the LEDs will be on. If you want to change the LEDs for one 74595, just change its byte to what you want (say %10101010 to have alternating LEDs on) and shift out ALL THE BYTES.

If you want randon LEDs on, set the byte to a random number....and SHIFT OUT ALL THE BYTES. You don't have to change all the bytes every time, but you do have to SHIFT THEM ALL OUT EVERY TIME.

Using multiple data lines only confuses this.



The picture below shows an instrument designed to my patent (designed by an EE). All of the LEDs are controlled by 74595s on A SINGLE DATA STREAM. Many times per second. And the 74595s could handle many more without breaking a sweat.

Don't try to be creative when you don't even understand THE BASIC CONCEPT. As Beau's videos show, controlling numerous LEDs from one data stream very quickly is easy.

Don't draw more schematics. Don't lay out more circuit boards. Unless and until you somehow manage to understand the basic concepts.

Of course I know this well-intentioned advice will be ignored. I have tried and failed.

Screenshot_20250128_092150_Facebook.jpg
 
here is the software PWM thai I edited
Code:
}
'Program: CHRISTMAS STAR:

Device = 18F43K22
Clock = 8

// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true       // automatically call setalldigital
Include "setdigitalio.bas"

// hardware
Dim INDEX  As LongWord  //4294967295
Dim Counter As Word
Dim Counter_up As Word
Dim Counter_down As Word
Dim m As Byte
Dim w As Byte
Dim x As Byte
Dim y As Byte
Dim z As Byte
Dim bright As Word
Dim dimmer As Word
Dim Bright_1 As LongWord        // a wider range of settings FOR A SMOOTHER TRANSITION
Dim Dimmer_1 As LongWord
Dim Bright_2 As LongWord        // a wider range of settings
Dim Dimmer_2 As LongWord

Dim SUB_COUNT As LongWord
Const BLUE_A(16)As Byte= (%00000000,
                          %00000000,
                          %00100000,  //
                          %00010000,    //
                          %00000000,
                          %00000000,
                          %00000000,
                          %00000000,  //xxxxxxxxxxxx2                                     
                          %00000000,
                          %00000000,
                          %00100000,  //
                          %00010000,    //
                          %00000000,
                          %00000000,
                          %00000000,
                          %00000000)
                          
                            
Const BLUE_B(16)As Byte=  (%10000000,  //
                          %01000000,    //
                          %00100000,  //
                          %00010000,    //
                          %00001000,  //
                          %00000000,
                          %00000000,
                          %00000000, //xxxxxxxxxxx5
                          %10000000,  //
                          %01000000,    //
                          %00100000,  //
                          %00010000,    //
                          %00001000,  //
                          %00000000,
                          %00000000,
                          %00000000)
                          
                          
Const BLUE_C(16) As Byte=  (%10000000, //
                           %01000000,   //
                           %00100000, //
                           %00000000,
                           %00001000,     //
                           %00000100,   //
                           %00000010, //
                           %00000000,    //xxxxxxxxxxxxxxxxxxxx6
                           %10000000, //
                           %01000000,   //
                           %00100000, //
                           %00000000,
                           %00001000,     //
                           %00000100,   //
                           %00000010, //
                           %00000000)                               
                          
Const BLUE_D(16) As Byte=  (%10000000,
                           %01000000,//
                           %00100000,  //
                           %00010000,    //
                           %00000000,
                           %00000000,
                           %00000000,
                           %00000001, // xxxxxxxxxx5
                           %10000000,
                           %01000000,//
                           %00100000,  //
                           %00010000,    //
                           %00000000,
                           %00000000,
                           %00000000,
                           %00000001) //                                                                                 

                        
                                                            
Const WHITE_A(8)As Byte= (%10000000,
                          %01000000,
                          %00000000,
                          %00010000,
                          %00001000,
                          %00000100,
                          %00000010,
                          %00000001)                                       
                          
Const WHITE_B(8)As Byte= (%00000000,
                          %00000000,
                          %00000000,
                          %00000000,
                          %00000000,
                          %00000100,
                          %00000010,
                          %00000001)
                          
                          
Const WHITE_C(8) As Byte= (%00000000,
                           %00000000,
                           %00000000,
                           %00010000,
                           %00000000,
                           %00000000,
                           %00000000,
                           %00000001)                             
                          
Const WHITE_D(8) As Byte= (%10000000,
                           %00000000,
                           %00000000,
                           %00000000,
                           %00001000,
                           %00000100,
                           %00000010,
                           %00000000)
                                                    
Const BLUE_E(16)As Byte =  (%00000100,
                           %00000010,
                           %00000001,  //3
                           %00000000,
                           %00000000,
                           %00000100,
                           %00000010,
                           %00000001,
                           %00000100,
                           %00000010,
                           %00000001,
                           %00000000,
                           %00000000,
                           %00000100,
                           %00000010,
                           %00000001)
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Const WHITE_Af(1)As Byte=(%11100111)

//-------------------------------------
//PATTERN SUBROUTES
Sub FLICKER_1()
INDEX = 1
Repeat

 
For x = 0 To 7           //WHITE
For z = 0 To 7          //BLUE
  PORTA = WHITE_A(x)
    DelayMS(1000)
  PORTA = BLUE_A(z)
    DelayUS(50)
  PORTB = WHITE_B(x)
    DelayMS(1000)
  PORTB = BLUE_B(z)
    DelayUS(50)
  PORTC = WHITE_C(x)
    DelayMS(1000)
  PORTC = BLUE_C(z)
    DelayUS(50)
  PORTD = WHITE_D(x)
    DelayMS(1000)
  PORTD = BLUE_D(z)
    DelayUS(50)   
  PORTE = BLUE_E(z)
    DelayUS(50)
    INDEX = (INDEX + 1)
Next   
Next
 
  Until INDEX >= 10000
 
End Sub



Sub FLICKER_2()
INDEX =1 
Counter_down = 1
Repeat
For x = 0 To 7
For z = 0 To 16       //all the blue leds
    PORTA = WHITE_A(x)
    DelayUS(Counter_down)
    PORTA = BLUE_A(z)
     DelayUS(25)
      
   PORTB = WHITE_B(x)
    DelayUS(Counter_down)
    PORTB = BLUE_B(z)
    DelayUS(25)
      
   PORTC = WHITE_C(x)
    DelayUS(Counter_down)
   PORTC = BLUE_C(z)
     DelayUS(25)
      
   PORTD = WHITE_D(x)
    DelayUS(Counter_down)
     PORTD = BLUE_D(z)
     DelayUS(25)
    
    PORTE = BLUE_E(z)
     DelayUS(10)
                 INDEX = (INDEX + 1)
                 Counter_down = (Counter_down + 1)    //dimming effect
    Next
    Next
    If Counter_down >= 2000
    Then
    Counter_down = 1             //reset counter_down back to 1
    End If
    Until INDEX >= 10000
 End Sub
 
Sub FLICKER_3()       //gradual dim to bright
INDEX = 1
Counter = 5
Repeat

 
For x = 0 To 7
For z = 0 To 7
  PORTA = WHITE_A(x)
    DelayUS(Counter)
  PORTA = BLUE_A(z)
    DelayUS(50)
  PORTB = WHITE_B(x)
    DelayUS(Counter)
  PORTB = BLUE_B(z)
    DelayUS(50)
  PORTC = WHITE_C(x)
    DelayUS(Counter)
  PORTC = BLUE_C(z)
    DelayUS(50)
  PORTD = WHITE_D(x)
    DelayUS(Counter)
  PORTD = BLUE_D(z)
    DelayUS(50)   
  PORTE = BLUE_E(z)
    DelayUS(50)
    INDEX = (INDEX + 1)
Next   
Next
  Counter = (Counter +1)
  Until INDEX >= 10000
End Sub   
//zzzzzzzzzzzzzzzzzzzzzzzzzz
Sub All_off()
   PORTE=%000
   PORTD=%00000000
   PORTC=%00000000
   PORTA=%00000000
   PORTB=%00000000 
End Sub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzz


Sub Fade()

 bright = 5000
 dimmer = 1   
 Bright_1 = 1              // bright_1 is ON  time variable
 Dimmer_1 = 5000           //dimmer_1 is OFF time variable
Repeat
  PORTA = %11011111
  PORTB = %00000111
  PORTC = %00010001
  PORTD = %10001110
  PORTE = %000
  DelayUS(Bright_1) 
  PORTA = %00000000
  PORTB = %00000000
  PORTC = %00000000
  PORTD = %00000000
  // DIMMING
  DelayUS (Dimmer_1) 
  Bright_1 = (Bright_1 +1)   // increase ON time BY 1
  Dimmer_1 = (Dimmer_1 - 1)  //decrease OFF time BY 1
 
 Until
 Bright_1 >= 3000            //HIGH BRIGHT
 
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//reset values
  Bright_2 = 5000
  Dimmer_2 = 1
 //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
Repeat
  PORTA = %11011111
  PORTB = %00000111
  PORTC = %00010001
  PORTD = %10001110
 
  DelayUS(Bright_1) 
  PORTA = %00000000
  PORTB = %00000000
  PORTC = %00000000
  PORTD = %00000000
  DelayUS(Dimmer_2)           // full dim          FIRST PASS IN LOOP
  Bright_2 = (Bright_2 - 1)
  Dimmer_2 = (Dimmer_2 + 1)
 
 Until
 Bright_2 = 1
  
//reset valuesxxxxxxxxxxxxxx 
  Bright_2 = 1
  Dimmer_2 = 5000
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
End Sub
//zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz                         
//-------------------------------------
// start of main program
//-------------------------------------
main:
// init hdw
               // LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0      // SET ALL PORTS AS OUTPUTS
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
   PORTE=%000         //TURN OFF ALL PORTS
   PORTD=%00000000
   PORTC=%00000000
   PORTA=%00000000
   PORTB=%00000000   

Bright_1 = 0
Dimmer_1 = 0
Bright_2 = 0
Dimmer_2 = 0
setalldigital
While true
Fade()       //ADD A COUNTER TO MAKE IT LONGER

FLICKER_1()
 All_off()          // indicates sequence change
 DelayMS(50)
 FLICKER_2()
 All_off()        // indicates sequence change
 DelayMS(50)
 FLICKER_3()

 
Wend
 {
 
 All_off()        // indicates sequence change
 DelayMS(50) 
 Wend
 {
 
While TRUE
 bright_1 = 1              // bright_1 is ON  time variable
 dimmer_1 = 5000           //dimmer_1 is OFF time variable
repeat
  led1 = 1                 //ON
  delayus(bright_1)        //AMOUNT OF TIME ON
  led1 = 0                 // OFF
  delayus (dimmer_1)       //AMOUNT OF TIME OFF
  bright_1 = (bright_1 +1)   // increase ON time BY 1
  dimmer_1 = (dimmer_1 - 1)  //decrease OFF time BY 1
 until
 bright_1 >= 5000            //HIGH BRIGHT
 
 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//reset values
  bright_2 = 5000
  dimmer_2 = 1
  LED2 = 1                    // LED2 COMES ON WHEN LED1 STARTS FROM HIGH BRIGHT TO FULL DIM
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 
 repeat
  led1 = 1                    //ON TIME
  delayus(BRIGHT_2)           // LED is full brightness  FIRST PASS IN LOOP
  led1 = 0                    //OFF TIME
  delayus(DIMMER_2)           // full dim          FIRST PASS IN LOOP
  bright_2 = (bright_2 - 1)
  dimmer_2 = (dimmer_2 + 1)
 until
 bright_2 = 1                  // FULL DIM
//reset valuesxxxxxxxxxxxxxx 
  bright_2 = 1                 //RESET VARIABLES
  dimmer_2 = 5000

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
wend
 
Last edited:
I'm sure your scheme will work as well as your ability to post code as shown above. Do you even look at what you post?

Have fun. You MIGHT make something work in time for Xmas 2026.

1747354.jpg
 
I think I sprained my brain figuring out what part of that... um..... mess has anything ANYTHING to do with shift registers!
 
I mean here is my bit banged Arduino code that I used in my clock to shift the data. Anyone worth their weight should be able to convert it into just about any language they wanted. ... You could probably fold it into a single line of code. No need to throw a huge bloated library at it for a solution.

Note: The 595 is so fast, that code delays were not necessary.

Code:
void LoadClock(int _Data){
      for (int Bit = 0; Bit < 8; Bit++){
        digitalWrite(Data,bitRead(_Data,Bit));
        digitalWrite(ShiftClock,HIGH);
        digitalWrite(ShiftClock,LOW);
      }
      digitalWrite(RegClock,HIGH);
      digitalWrite(RegClock,LOW);
}
 
the code in post#303 was pertaining only to a software form of PWM I wrote couple years ago
And yes it works
If I have RED and GREEN LEDs on the perimeter chasing around the tree I need one data source
RED LEDs = 10101010
GREEN LEDs = 01010101
for the field I need a separate data source, so the field LEDs are not chasing each other. These using PWM maybe from the code in post #303
At least that what I think
 
If I have RED and GREEN LEDs on the perimeter chasing around the tree I need one data source
RED LEDs = 10101010
GREEN LEDs = 01010101

That will give you ALL red or ALL green. They won't be chasing. That's what you want, dump the '595s and wire the red LEDs to one honking large mosfet and the green LEDs to another honking large mosfet.

The chasing effect I mentioned was one small possibility out of an infinite number of things that could be done. Shrug. Why limit the possibilities from the start?

You just don't get this. It's beyond you ability to understand apparently. I'm done trying to explain. If 3 or 4 people are telling you the same thing, and you choose to ignore the advice and repeated explanations, don't come crying to them when wanderer pile of crap you do doesn't work.

And please properly format or delete your code in post #303. It goes on for FORTY ONE SCREENS on my phone.

Screenshot_20250129_110315_Edge.jpg


Screenshot_20250129_110020_Edge.jpg


I had to include both images. Both reflect my feelings on this.
 
MrDEB, these pictures show your code as it appears in post #303. All 41 screens of it! Crap. Even thumbnail take 8 screens. No pictures – just go look at the mess!

Do you not know how to edit? Or you expect people to deal with your crap?


Screenshot_20250129_182811_Edge.jpg
 
Why don't you EDIT it, and either delete the code or repost it properly?
 
after assembling a test board I discovered the 595's have no marking for pins
going to measure resistance from pin16? to pin 8? and hopefully compare readings with a dip 74hc595
applying 5v+I get 2 leds enabled QA and QG
 

Attachments

  • 74HC595 TEST BOARD2-2.pdf
    46 KB · Views: 27
"the 595's have no marking for pins" - What? This is absurd !! Take a clear picture and post it please.

"going to measure resistance from pin16? to pin 8?" --- might be better doing a diode check with a DMM
 
totally LOST
I assembled my test board., made several corrections to board but thinking maybe pressing the buttons in wrong order.
Maybe if I convert some Arduino code to swordfish?
getting lost just thinking about it
My plan is to connect a pic to the test board and maybe get this 74hc595 to work as designed?
any help with code?
 

Attachments

  • 74HC595 TEST BOARD2.pdf
    46.2 KB · Views: 21
here is what I have so far no clue on what to do next?
Code:
Device = 18F43K22
Clock = 8

// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true       // automatically call setalldigital
Include "setdigitalio.bas"
Include "SHIFT.BAS"
 Dim Clk As PORTB.3
 Dim w-DATA As PORTA.1
 Dim r-DATA As PORTA.4
 Dim LATCH As PORTB.4
 Dim RESET As PORTB.1
 Dim Leds As Byte
 Output (Clk)
 Output (w-DATA)
 Output (r-DATA)
 Output (LATCH)
 Output (Leds)
 
 Leds = 0
 update (shiftreister)
 DelayMS(500)
 update (shiftreister)
 LATCH = 0
 shiftout (DATA, Clock,lsbfirst, Leds)
 LATCH = 1
 

Latest threads

Back
Top