In SX Microcontrollers, SX/B Compiler and SX-Key Tool, DigitalDj wrote: This is the code of Bean's that I need to add in a way to make it addressable. I guess I could probably do it a couple of ways but I wanted to get some input on the best way. For 1 I could put it right in with the !PWM to control the outputs or use some pins on the SX and when the pins are low I could set them as 1, 2 and 3. I'm not real sure on how to pull this off on the pin configuration and the code. I would appreciate any ideas and help! Thanks, Kevin [code] ' ========================================================================= ' ' File...... PWM64.SXB ' Compiler.. SX/B Version 1.22 ' Purpose... 64 Multiplexed Channels of PWM (For LED matrix control) ' Author.... Hitt Consulting ' E-mail.... [url=terry@hittconsulting.com]terry@hittconsulting.com[/url] ' Started... June 15, 2005 ' Updated... ' ' ========================================================================= ' ------------------------------------------------------------------------- ' Program Description ' ------------------------------------------------------------------------- ' Accepts serial data at 9600 baud and provides 64 channels of duty cycle modulated PWM ' Serial data is sent with a header of "!PWM" then 64 bytes of data (0=full off, 255=full on) ' ' OSC1&2 = 50Mhz resonator ' Port RA.3 = Serial input ' Port RB = Rows 0 to 7 (Active High) ' Port RC = Column 0 to 7 (Active High, use NPN transistor as column driver) ' ' 10K ' /MCLR -/\/\/\----- Vdd Pin ' ' 10K ' RA.3 -/\/\/\-----< Serial Input (9600 baud 8N1 Inverted) ' ' 220 Ohm ' RB.0 -/\/\/\-----> PWM Output Row 0 ' ' 220 Ohm ' RB.1 -/\/\/\-----> PWM Output Row 1 ' ' 220 Ohm ' RB.2 -/\/\/\-----> PWM Output Row 2 ' ' 220 Ohm ' RB.3 -/\/\/\-----> PWM Output Row 3 ' ' 220 Ohm ' RB.4 -/\/\/\-----> PWM Output Row 4 ' ' 220 Ohm ' RB.5 -/\/\/\-----> PWM Output Row 5 ' ' 220 Ohm ' RB.6 -/\/\/\-----> PWM Output Row 6 ' ' 220 Ohm ' RB.7 -/\/\/\-----> PWM Output Row 7 ' ' 1K Ohm ' RC.0 -/\/\/\-----> Column Output 0 (To base of NPN column driver) ' ' 1K Ohm ' RC.1 -/\/\/\-----> Column Output 1 (To base of NPN column driver) ' ' 1K Ohm ' RC.2 -/\/\/\-----> Column Output 2 (To base of NPN column driver) ' ' 1K Ohm ' RC.3 -/\/\/\-----> Column Output 3 (To base of NPN column driver) ' ' 1K Ohm ' RC.4 -/\/\/\-----> Column Output 4 (To base of NPN column driver) ' ' 1K Ohm ' RC.5 -/\/\/\-----> Column Output 5 (To base of NPN column driver) ' ' 1K Ohm ' RC.6 -/\/\/\-----> Column Output 6 (To base of NPN column driver) ' ' 1K Ohm ' RC.7 -/\/\/\-----> Column Output 7 (To base of NPN column driver) ' ------------------------------------------------------------------------- ' Device Settings ' ------------------------------------------------------------------------- DEVICE SX28, OSCHS2, TURBO, STACKX, OPTIONX, BOR42 FREQ 50_000_000 ' ------------------------------------------------------------------------- ' IO Pins ' ------------------------------------------------------------------------- SerialInPin VAR RA.3 ' ------------------------------------------------------------------------- ' Constants ' ------------------------------------------------------------------------- Baud CON "N11034" ' Adjusted baud rate for 9600 baud incoming 9600/0.870 ' This adjustment is need because the interrupt uses ' 130 cycles every 1000 clocks. So the main code only ' gets 870 cycles of every 1000 clocks. ' ------------------------------------------------------------------------- ' Variables ' ------------------------------------------------------------------------- ' Variables for PWM Interrupt Column VAR BYTE ' 1,2,4,8,16,32,64,128 DataPlace VAR BYTE ' Pointer to PWM values PWM_Count VAR BYTE PWM_Values0 VAR BYTE (8) PWM_Values1 VAR BYTE (8) PWM_Values2 VAR BYTE (8) PWM_Values3 VAR BYTE (8) PWM_Values4 VAR BYTE (8) PWM_Values5 VAR BYTE (8) PWM_Values6 VAR BYTE (8) PWM_Values7 VAR BYTE (8) ' Variables for main code Count VAR BYTE SerialData VAR BYTE ' Set by subroutine "GetSerialChar" ' ------------------------------------------------------------------------- INTERRUPT ' ------------------------------------------------------------------------- ISR_Start: ' Entry and Exit code (37) cycles ' (93+37=130) cycles. NOTE: each path through the interrupt routine should be the ' same number of cycles, so the SERIN command works properly. ASM INC PWM_Count ' (1) Adjust the PWM count ' If the PWM value for each channel is less than ' PWM_Count then it should be high, othewise it ' should be low. JZ :AdjustColumn ' (2/4) NOP ' (1) JMP $+1 ' (3) JMP $+1 ' (3) JMP $+1 ' (3) JMP :ColumnOk ' (3) :AdjustColumn ADD DataPlace,#$08 ' (2) RL Column ' (1) JC :ResetColumn ' (2/4) MOV W,#$10 ' (1) SB DataPlace.4 ' (1/2) ADD DataPlace,W ' (1) JMP :ColumnOk ' (3) :ResetColumn MOV Column,#1 ' (2) MOV DataPlace,#PWM_Values0 ' (2) :ColumnOk MOV RC,Column ' (2) MOV __PARAM4,PWM_Count ' (2) Make copy of PWM_Count in global memory MOV FSR,DataPlace ' (2) Set FSR to address of 1st element of PWM values CJA IND,__PARAM4,:HIGH_B0 ' (4/6) CLRB RB.0 ' (1) JMP :DONE_B0 ' (3) :HIGH_B0 SETB RB.0 ' (1) NOP ' (1) :DONE_B0 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B1 ' (4/6) CLRB RB.1 ' (1) JMP :DONE_B1 ' (3) :HIGH_B1 SETB RB.1 ' (1) NOP ' (1) :DONE_B1 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B2 ' (4/6) CLRB RB.2 ' (1) JMP :DONE_B2 ' (3) :HIGH_B2 SETB RB.2 ' (1) NOP ' (1) :DONE_B2 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B3 ' (4/6) CLRB RB.3 ' (1) JMP :DONE_B3 ' (3) :HIGH_B3 SETB RB.3 ' (1) NOP ' (1) :DONE_B3 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B4 ' (4/6) CLRB RB.4 ' (1) JMP :DONE_B4 ' (3) :HIGH_B4 SETB RB.4 ' (1) NOP ' (1) :DONE_B4 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B5 ' (4/6) CLRB RB.5 ' (1) JMP :DONE_B5 ' (3) :HIGH_B5 SETB RB.5 ' (1) NOP ' (1) :DONE_B5 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B6 ' (4/6) CLRB RB.6 ' (1) JMP :DONE_B6 ' (3) :HIGH_B6 SETB RB.6 ' (1) NOP ' (1) :DONE_B6 INC FSR ' (1) CJA IND,__PARAM4,:HIGH_B7 ' (4/6) CLRB RB.7 ' (1) JMP :DONE_B7 ' (3) :HIGH_B7 SETB RB.7 ' (1) NOP ' (1) :DONE_B7 ENDASM ISR_Exit: RETURNINT 250 ' Prescaler at 1:4 = 1000 cycles or 20uSec = 256*20uSec=5.12mSec or 195 Hz ' ========================================================================= PROGRAM Start ' Allow startup code to zero PWM values ' ========================================================================= ' ------------------------------------------------------------------------- ' Subroutine Declarations ' ------------------------------------------------------------------------- GetSerialChar SUB 0 ' ------------------------------------------------------------------------- ' Program Code ' ------------------------------------------------------------------------- Start: TRIS_B=%00000000 ' All outputs TRIS_C=%00000000 ' All outputs ' Setup so at next interrupt will restart at column 0 PWM_Count = 255 DataPlace = PWM_Values7 Column = 128 ' Enable RTCC interrupt OPTION=$81 ' Enable RTCC interrupts, RTCC Prescaler = 1:4 Main: ' Wait for "!PWM" header GetSerialChar IF SerialData <> "!" THEN Main GetSerialChar IF SerialData <> "P" THEN Main GetSerialChar IF SerialData <> "W" THEN Main GetSerialChar IF SerialData <> "M" THEN Main ' Get Data for 64 PWM channels FOR Count=0 TO 7 GetSerialChar PWM_Values0(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values1(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values2(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values3(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values4(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values5(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values6(Count)=SerialData NEXT FOR Count=0 TO 7 GetSerialChar PWM_Values7(Count)=SerialData NEXT ' Do it again GOTO Main ' ------------------------------------------------------------------------- ' Subroutine Code ' ------------------------------------------------------------------------- GetSerialChar: SERIN SerialInPin,Baud,SerialData RETURN [/code] ---------- End of Message ---------- You can view the post on-line at: http://forums.parallax.com/forums/default.aspx?f=7&p=1&m=254111#m254377 Need assistance? Send an email to the Forum Administrator at forumadmin@parallax.com The Parallax Forums are powered by dotNetBB Forums, copyright 2002-2008 (http://www.dotNetBB.com)