#include <system.h>
#include <boostc.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA _CONFIG1H, _INTIO2_OSC_1H
#pragma DATA _CONFIG2H, _WDT_OFF_2H
#pragma DATA _CONFIG3H, _MCLRE_ON_3H
#pragma DATA _CONFIG4L, _LVP_OFF_4L
#define data latb.1
#define clock latb.4
#define latch lata.3
void main(void){
unsigned char x;
osccon=0x72; //8MHz osc
trisa=trisb=0;
while(1){
data=1; //shift in alternating 1's & 0's
for(x=0;x<8;x++){
clock=1;clock=0;
if(data==0)
data=1;
else
data=0;
}
latch=1;latch=0; //latch the data
delay_ms(170); //delay so we can see LEDs
data=0; //shift in alternating 0's & 1's
for(x=0;x<8;x++){
clock=1;clock=0;
if(data==0)
data=1;
else
data=0;
}
latch=1;latch=0; //latch the data
delay_ms(170); //delay so we can see LEDs
}
}
void main(void){
unsigned char x,y,temp1,temp2;
osccon=0x72; //8MHz osc
trisa=trisb=0;
while(1){
for(x=0;x<255;x++){
for(y=0;y<8;y++){
temp1=x;
temp2=temp1>>y;
temp2=temp2&0b00000001;
data=temp2;
clock=1;clock=0;
}
latch=1;latch=0;
delay_ms(170);
}
}
}
That C code is super easy to port to assembly. Pretty simple stuff. It's not like C is some kind of ultra cryptic language or anything.ok thanks for the info but anything in assembler thats the only thing I know at the moment and understand but thanks for the quick responses also is there a way to have more then one pin on at the same time say I have 1 shiftregister that has 12 outputs and 4 inputs once again ?
Hehehe!ty thats helped alot I also have a concern though about how the Multiplexing of a 3D LED cube works me and my teacher have spent a few days on trying to figure out how it works and stuff any help on this one as well all get converting the C or at least try too it looks soooo confusing haha it might help if you explain it like you said thanks once again and if I get it right its basically just putting lets say GP2 high, low, high, low so many times in a certain amount of time or do you have to send a string of bits bc im not sure how to do that
On my small 3x3x3 LED cube I just treated it like three stacked 9-bit digits. I was driving it directly - no shift registers - but that doesn't change anything. I simply set the bits I wanted lit on each "digit" and every time the timer interrupted it would light up the next "digit", or level. Writing this piece of code for the first time is pretty brain-grinding, but really it's not terribly complex.I also have a concern though about how the Multiplexing of a 3D LED cube works
There's no amount of time involved. You can shift bits in as fast or as slow as you like. What you do is put the bit value you want (0 or 1) on the data pin. Then toggle the clock high and low quickly (or slowly if you likeif I get it right its basically just putting lets say GP2 high, low, high, low so many times in a certain amount of time or do you have to send a string of bits bc im not sure how to do that
; Pin assignments: *
; *
; GP0 - Data input *
; GP1 - Clock input *
; GP2 - Latch input *
; GP3 - Used as a switch for Cycle of LED's *
; GP4 - Forth set of LEDS *
; GP5 - Switch for Random effect *
; *
; *
; *
;**********************************************************************
list p=12F509 ; list directive to define processor
#include <p12F509.inc> ; processor specific variable definitions
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
cblock 0x07
;***** VARIABLE DEFINITIONS
clock
data1
data0
latch
endc
;**********************************************************************
RESET_VECTOR CODE 0x3FF ; processor reset vector
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value
start
;******** Main Code
start
movlw b'001000' ; Configure only GP3 as a input
tris GPIO
loop
call data1 ; 1st bit High
call clock
call data0 ; 2nd bit Low
call clock
call data0 ; 3rd bit Low
call clock
call data0 ; 4th bit Low
call clock
call data0 ; 5th bit Low
call clock
call data0 ; 6th bit Low
call clock
call data0 ; 7th bit Low
call clock
call data0 ; 8th bit Low
call latch
;******** Subroutines
clock
movlw b'000010' ; Clock set
movwf GPIO
retlw 0
data1 movlw b'000001' ; Data pin high
movwf GPIO
retlw 0
data0 movlw b'000000' ; Data pin low
movwf GPIO
retlw 0
latch movlw b'000000'
movwf GPIO
retlw 0
END ; End of Program !
The shift register should be able to keep up with almost anything you throw at it (unless you're running some kind of huge clock rate). No delays necessary. You may have to put a nop in to avoid RMW (read-modify-write) problems, but definitely try it without first.Doesn't even matter how fast I do it so I won't need a delay in between each one?
High and back low again. Just blip it to latch the data, same as you just blip the clock to clock in bits.But toggle the clock in between each bit then after thats all done I just toggle the latch pin high and it should do what I want
What you'll usually do for a thing like this is build sequences of patterns that each level steps through. Put them in tables and just step through them at a steady rate. So writing all 9 bits each time is simple and automated. Once you write the engine (the hard part) it's just a matter feeding it different sequences of patterns (the fun and easy part).I might put in a call for a loop that just repeats a Low output so that I don't have to write out the whole 7 bits as low. I can call a loop if I have to. I'm not sure if there is a better way to write it ?
downtb db 0x00,0x00,0x00,0x00,0xff,0x01
db 0x00,0x00,0xff,0x01,0x00,0x00
db 0xff,0x01,0x00,0x00,0x00,0x00
rolltb db 0x24,0x01,0x00,0x00,0x00,0x00
db 0x49,0x00,0x00,0x00,0x00,0x00
db 0x92,0x00,0x00,0x00,0x00,0x00
db 0x00,0x00,0x92,0x00,0x00,0x00
db 0x00,0x00,0x00,0x00,0x92,0x00
db 0x00,0x00,0x00,0x00,0x49,0x00
db 0x00,0x00,0x00,0x00,0x24,0x01
db 0x00,0x00,0x24,0x01,0x00,0x00
floptb db 0xe0,0x00,0xe0,0x00,0xe0,0x00
db 0x03,0x01,0x1c,0x00,0xe0,0x00
db 0x00,0x00,0x00,0x00,0xff,0x01
db 0xe0,0x00,0x1c,0x00,0x03,0x01
db 0x03,0x01,0x03,0x01,0x03,0x01
db 0x03,0x01,0x1c,0x00,0xe0,0x00
db 0xff,0x01,0x00,0x00,0x00,0x00
db 0xe0,0x00,0x1c,0x00,0x03,0x01
flshtb1 db 0x10,0x00,0x10,0x00,0x10,0x00
db 0x02,0x00,0x10,0x00,0x80,0x00
db 0x00,0x00,0x92,0x00,0x00,0x00
db 0x80,0x00,0x10,0x00,0x02,0x00
db 0x08,0x00,0x08,0x00,0x08,0x00
db 0x01,0x00,0x08,0x00,0x40,0x00
db 0x00,0x00,0x49,0x00,0x00,0x00
db 0x40,0x00,0x08,0x00,0x01,0x00
db 0x04,0x00,0x04,0x00,0x04,0x00
db 0x00,0x01,0x04,0x00,0x20,0x00
db 0x00,0x00,0x24,0x01,0x00,0x00
db 0x20,0x00,0x04,0x00,0x00,0x01
;**********************************************************************
; Pin assignments: *
; *
; GP0 - Data input *
; GP1 - Clock input *
; GP2 - Latch input *
; GP3 - Used as a switch for Cycle of LED's *
; GP4 - Forth set of LEDS *
; GP5 - Switch for Random effect *
; *
; *
; *
;**********************************************************************
list p=12F509 ; list directive to define processor
#include <p12F509.inc> ; processor specific variable definitions
__CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _IntRC_OSC
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
cblock 0x07
;***** VARIABLE DEFINITIONS
clock
data1
data0
latch
endc
;**********************************************************************
RESET_VECTOR CODE 0x3FF ; processor reset vector
; Internal RC calibration value is placed at location 0x3FF by Microchip
; as a movlw k, where the k is a literal value.
MAIN CODE 0x000
movwf OSCCAL ; update register with factory cal value
start
;******** Main Code
start
movlw b'001000' ; Configure only GP3 as a input
tris GPIO
loop
call LED1
goto loop
;******** Subroutines
clock
movlw b'000010' ; Clock set 1
movwf GPIO
movlw b'000000' ; Clock set 0
movwf GPIO
retlw 0
data1 movlw b'000001' ; Data pin high
movwf GPIO
retlw 0
data0 movlw b'000000' ; Data pin low
movwf GPIO
retlw 0
latch movlw b'000100'
movwf GPIO
movlw b'000000'
movwf GPIO
retlw 0
LED1 call data1
call clock
call data0
call clock
call data0
call clock
call data0
call clock
call data0
call clock
call data0
call clock
call data0
call clock
call data0
call clock
call latch
retlw 0
END ; End of Program !
What I mean by that is I built a piece of code (an engine) that takes whatever sequence of patterns that I build (that meet the requirements of the engine) and displays them. I don't have to mess with it - it just works. Feed it sequences of patterns and it makes it happen.Not too sure what your getting at with the whole engine thing
That's incredibly difficult to understand (ever heard of punctuation? try using some!), but I think I get the gist of what you're saying. Yes, that's an "engine". I just feed it a pointer to the pattern I want and it takes care of the rest.If im correct you mean to make it so instead of calling like data1 data0 etc its just one call and it makes it all so like if I wanted LED1 on I would do something like this instead of what I have and im wondering is there a way to lets say just write it like this "10000000" then the pic then takes that and outputs it like that but adding the clock call in between each bite ? it might be easyer when making the cube then I won't have this long list of LED's and just be able to write it as one number and then the PIC takes it from there seperates it and then the Shift Register outputs it?
It is a fair bit of code. My asm program to run my cube, with seven patterns, was around 954 bytes. Your 12F509 has 1024, so even if your code isn't as tight it should fit. You might have to lose a couple patterns. So what?Just because its going to take alot of code and I don't think the PIC will be able to hold that much
Umm... Put your brain in gear, get some scribble paper and calculator ready and start coding!how would I then go about writing a engine to allow me to just give it a 8 bit sequence and it will take that and display it?
This might be a bit much for you if you're still at the beginner stage. You'll need to be able to use and understand timers and interrupts to get this to work right.I'm sorry. I'm new to PIC's and just know some of the basic commands like changing bits to high,low and loops not too much of the other stuff. Sorry.
That's a start!Move '100000000' into D
Take first bit, Change GPO to what first bit is
Clock it
Take second bit, Change GP0 to what second bit is
Clock it
etc...
Latch
Goto next sequence
Use RLF or RRF to rotate the high or low bit (your choice) into the carry. Then do a check of the carry flag to see if it's 1 or 0 to determine what to put on the data pin to be shifted next.haha can you atleast tell me how to take a single bit from a sequence after that everything should be simple thats the thing im stuck on
That's why I said you might be a bit too green to tackle something like this.Ya you lost me at RLF haha wow this may seem alot more complicated then I thought it would be
A byte is not a string. And rotating the bit you want to test into the carry is pretty darn simple.there's no simple way to take a string and seperate it is there?
Oh! This is that PIC. I really would recommend you use a bigger, more capable PIC for a job like this. Without interrupts, and with so few resources, this will be hard! Get a 16F88 or better yet, an 18F1320. Or even a bigger PIC. The little 8-pinners are tough for beginners. They're tight for resources and pins. Great for saving money if you're in production or your project is very simple, but tough to do more complex things without a lot of planning and knowhow.the only problem is that the 509 doesn't have a interrupt so im not sure what to do from there.
Learning how to isolate, move and test bits, nybbles and whole bytes is what it's all about when programming PICs (or any computer) in any but the most elementary way. You must understand bit operations fluently before you'll be able to complete a project like this.I know how to place the string into a variable then read that variable im just not sure how to take each bit apart. I also know how how to write it too the pin I just can't take the bit's apart and thats the problem bc soon as I get that my code goes from a whole bunch of lines to almost half and making sequences are so much easier as well.
Not true at all. You just keep rotating bits in and checking them, and putting the results on the data line and clocking them out.Also I think if I understand it right your way of doing it with RLF will only allow me to have on pin on at a time
Start by breadboarding up your 12F509 and the 74HC595 with 8 LEDs. Tinker with getting the 595 to light LEDs under your control. Learn to use rlf and rrf.ok ya I might have to work up to it like you said can you give me a few project names or links too where I can start learning more about this ?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?