Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SPI and RGB LED tape

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here
View previous topic :: View next topic  
Author Message
SZTRAD

Bascom Member



Joined: 30 Dec 2019
Posts: 165

blank.gif
PostPosted: Wed Feb 24, 2021 2:21 pm    Post subject: SPI and RGB LED tape Reply with quote

Hi
The last time I pointed it out, I tried.
Control of the RGB LED tape using the SPI peripheral.
Theoretically, this method should be faster than using TCB, which I showed last time, but unfortunately the engineers in the microchip made a mistake and cannot start timing with CLK2. I mean, it's generating weird pulses at least on the sample I have in the development board.
So if anyone ever needs it, here's an example.

Code:

  $regfile = "atXtiny412.dat"
$crystal = 20000000
$hwstack = 16
$swstack = 16
$framesize = 24

'set the system clock and prescaler
Config Sysclock = 16_20mhz , Prescale = 1

dim color(3) as byte
dim delka as word


Declare sub vys(color() as byte,  byval delka as byte)
'Configured SPI
spi0_ctrla=&B00100001
spi0_ctrlb=&B01000100
config porta.6=output
portmux_ctrlb=&B00000100            'alternative SPI output
porta_pin6ctrl=&B10000000           'MOSI output negation



'Number of LEDs  x3
delka = 192


do
'Configured color
color(1)= 0
color(2)= 0
color(3)= 0
call vys (color(1),delka)
wait 1
color(1)= 255
color(2)= 0
color(3)= 0
call vys (color(1),delka)
wait 1
color(1)= 0
color(2)= 255
color(3)= 0
call vys (color(1),delka)
wait 1
color(1)= 0
color(2)= 0
color(3)= 255
call vys (color(1),delka)
wait 1
loop




sub vys (color() as byte,  byval delka as byte)
 dim maska as byte
 dim i as word
 dim pom as byte
 dim pom1 as byte
 dim m as byte
    i=0
   pom1=0
  disable interrupts    'Turn off interrupts to be sure
  for  i= delka to 0 step -1
       pom1=pom1+1
       maska = &B10000000
       m=8
      while m > 0

            pom=color(pom1)
            pom=maska and pom
            if pom>0 then
             spi0_data=&B10001111    'Number of timer pulses for state H

            else
             spi0_data=&B11011111     'Number of timer pulses for state L

            end if
             while spi0_intflags.7=0   'waiting for byte to drop
             wend
            spi0_intflags.7=1           'flag zero
            m=m-1


        shift maska,right
      wend
      if pom1=3 then
      pom1=0
      end if
  next i
  enable Interrupts

 waitus 70                     'Latch WS
 end sub


RS
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> Share your working BASCOM-AVR code here All times are GMT + 1 Hour
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
You cannot attach files in this forum
You cannot download files in this forum