Microcontroller › 8051 › help me with 3*3 led cube with 89c51 ?
- This topic has 6 replies, 3 voices, and was last updated 14 years, 1 month ago by dagakshay.
-
AuthorPosts
-
October 20, 2010 at 6:10 pm #448Paras WadherParticipant
Is it possible to drive 3*3 led cube with 89c51 ?
If yes can you help me with the program?
I have made 4*4 Led cube using atmel 16 16pu( i got program ang circuit diagram from instructables ).
October 21, 2010 at 4:41 am #5108dagakshayParticipantfirst let me clear you are going for “3*3 2-dimensional square array” or “3*3*3 3-dimensional cube array”
if you are talking about 3-d array yes it is possible with at89c51
formula for 3-d array i/o lines = (n*n)+n*(m-1) // if u not using encoder and decoders
where n is size of cude like if y are going for 3*3*3 cube then (n*n*m)
and m is no. of floors.
and also plz specify what excetly you want in that.
October 21, 2010 at 6:37 am #5111nitesh karangutkarParticipanti am also working on it but i dont having the sourcecode for 3*3 LED electronic dice !!!!!!!!!! so if u have then send me it or paste here …. pls i want it urgently !!!!!!!! help me !!!!!!!!!!!!
October 21, 2010 at 2:33 pm #5114Paras WadherParticipant/I need code for 3*3*3 led cube running from 89c51 and how to upload bin file to 89c51 m using tx-rx of max232 .Help
/ ############################################
//
// 4x4x4 LED Cube project// ############################################
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>// Define USART stuff
// CPU speed and baud rate:
#define FOSC 14745600
#define BAUD 9600
// Are used to calculate the correct USART timings
#define MYUBRR (((((FOSC * 10) / (16L * BAUD)) + 5) / 10) – 1)// Define masks used for status LEDs and input buttons.
#define LED_GREEN 0x01
#define LED_RED 0x02
#define BUTTON 0x08
// Define port used for status and input.
#define LED_PORT PORTB
#define BUTTON_PORT PORTB// Define masks for the layer select.
#define LAYER1 0x80
#define LAYER2 0x40
#define LAYER3 0x20
#define LAYER4 0x10
#define LAYERS 0xf0 // All layers
#define LAYERS_R 0x0f // The inverse of the above.
#define LAYER_PORT PORTD// Define LED grid ports
// Each of the grid ports are connected to two rows of leds.
// The upper 4 bits is one row, the lower 4 bits are one row.
#define GRID1 PORTC
#define GRID2 PORTAvoid ioinit (void); // initiate IO on the AVR
void bootmsg (void); // blink some leds to indicate boot or reboot
void delay_ms (uint16_t x); // delay function used throughout the program
void led_red(unsigned char state); // led on or off
void led_green(unsigned char state);
void launch_effect (int effect); // effect program launcher// *** Cube buffer ***
// The 3D image displayed on the cube is buffered in a 2d array ‘cube’.
// The 1st dimension in this array is the Z axis of the cube.
// The 2nd dimension of the array is the Y axis.
// Each byte is a stripe of leds running along the X axis at the given
// Z and Y coordinates.
// Only the 4 lower bits are used, since the cube is only 4x4x4.
// This buffer design was chosen to have code compatability with a 8x8x8 cube.
// “volatile” makes the variables reachable from within the interrupt functions
volatile unsigned char cube[4][4];// We sometimes want to draw into a temporary buffer so we can modify it
// before writing it to the cube buffer.
// e.g. invert, flip, reverse the cube..
volatile unsigned char tmpcube[4][4];// What layer the interrupt routine is currently showing.
volatile unsigned char current_layer;// Low level geometric functions
#include “draw.c”// Static animation data
#include “frames.c”// Fancy animations to run on the cube
#include “effect.c”int main (void)
{
// Initiate IO ports and peripheral devices.
ioinit();
// Indicate that the device has just booted.
bootmsg();int x;
int i;
int z;// Set the layer to start drawing at
current_layer = 0x00;
// Enable interrupts to start drawing the cube buffer.
// When interrupts are enabled, ISR(TIMER2_COMP_vect)
// will run on timed intervalls.
sei();// Main program loop.
while (1)
{
for (i=0;i<13;i++)
{
launch_effect(i);
}
// Comment the loop above and uncomment the line below
// if you want the effects in random order (produced some bugs.. )
//launch_effect(rand()%13);
}}
// Launches one of those fancy effects.
void launch_effect (int effect)
{
switch (effect)
{
// Lights all the layers one by one
case 0:
loadbar(1000);
break;
// A pixel bouncing randomly around
case 1:
// blink
boingboing(150,500,0×03,0x01);
break;
// Randomly fill the cube
// Randomly empty the cube
case 2:
fill(0x00);
random_filler(100,1,500,1);
random_filler(100,1,500,0);
break;
// Send voxels randomly back and forth the Z axis
case 3:
sendvoxels_rand_z(150,500,2000);
break;
// Spinning spiral
case 4:
effect_spiral(1,75,1000);
break;
// A coordinate bounces randomly around the cube
// For every position the status of that voxel is toggled.
case 5:
// toggle
boingboing(150,500,0×03,0x02);
break;
// Random raindrops
case 6:
effect_rain(20,5000,3000,500);
break;
// A snake randomly bounce around the cube.
case 7:
// snake
boingboing(150,500,0×03,0x03);
break;
// Spinning plane
case 8:
effect_spinning_plane(1,50,1000);
break;
// set x number of random voxels, delay, unset them.
// x increases from 1 to 20 and back to 1.
case 9:
random_2();
break;
// Set all 64 voxels in a random order.
// Unset all 64 voxels in a random order.
case 10:
random_filler2(200,1);
delay_ms(2000);
random_filler2(200,0);
delay_ms(1000);
break;
// bounce a plane up and down all the directions.
case 11:
flyplane(“z”,1,1000);
delay_ms(2000);
flyplane(“y”,1,1000);
delay_ms(2000);
flyplane(“x”,1,1000);
delay_ms(2000);
flyplane(“z”,0,1000);
delay_ms(2000);
flyplane(“y”,0,1000);
delay_ms(2000);
flyplane(“x”,0,1000);
delay_ms(2000);
break;
// Fade in and out at low framerate
case 12:
blinky2();
break;
}
}// ** Diagnostic led functions **
// Set or unset the red LED
void led_red(unsigned char state)
{
if (state == 0x00)
{
LED_PORT &= ~LED_RED;
} else
{
LED_PORT |= LED_RED;
}
}// Set or unset the green LED
void led_green(unsigned char state)
{
if (state == 0x00)
{
LED_PORT &= ~LED_GREEN;
} else
{
LED_PORT |= LED_GREEN;
}
}// Cube buffer draw interrupt routine
ISR(TIMER2_COMP_vect)
{// AND the reverse bitmask onto the layer port.
// This disables all the layers. rendering all the leds off.
// We don’t want to see the cube updating.
LAYER_PORT &= LAYERS_R;// Take the current 2D image at the current layer along the Z axis
// and place it on the LED grid.
GRID1 = (0x0f & cube[current_layer][0]) | (0xf0 & (cube[current_layer][1] << 4));
GRID2 = (0x0f & cube[current_layer][2]) | (0xf0 & (cube[current_layer][3] << 4));// Enable the apropriate layer
LAYER_PORT |= (0x01 << (7 – current_layer));// The cube only has 4 layers (0,1,2,3)
// If we are at layer 3 now, we want to go back to layer 0.
if (current_layer++ == 3)
current_layer = 0;
}void ioinit (void)
{
// ### Initiate I/O
// Data Direction Registers
// Bit set to 1 means it works as an output
// Bit set to 1 means it is an input
DDRA = 0xff; // Inner cube byte
DDRB = 0xf7; // ISP and 0-1: led. 3: button
DDRC = 0xff; // Outer cube byte
DDRD = 0xff; // Layer select
// Set all ports OFF, and enable pull up resistors where needed.
PORTA = 0x00;
PORTC = 0x00;
PORTB = 0x08; // Enable pull up button.
PORTD = 0x00;// ### Initiate timers and USART
// Frame buffer interrupt
TCNT2 = 0x00; // initial counter value = 0;
TIMSK |= (1 << OCIE2); // Enable CTC interrupt
// Every 1024th cpu cycle, a counter is incremented.
// Every time that counter reaches 15, it is reset to 0,
// and the interrupt routine is executed.
// 14745600/1024/15 = 960 times per second
// There are 4 layers to update..
// 14745600/1024/15/4 = 240 FPS
// == flicker free
OCR2 = 15; // interrupt at counter = 15
TCCR2 = 0x05; // prescaler = 1024
TCCR2 |= (1 << WGM01); // Clear Timer on Compare Match (CTC) mode// Initiate RS232
// USART Baud rate: 9600
UBRRH = MYUBRR >> 8;
UBRRL = MYUBRR;
// UCSR0C – USART control register
// bit 7-6 sync/ascyn 00 = async, 01 = sync
// bit 5-4 parity 00 = disabled
// bit 3 stop bits 0 = 1 bit 1 = 2 bits
// bit 2-1 frame length 11 = 8
// bit 0 clock polarity = 0
UCSRC = 0b10000110;
// Enable RS232, tx and rx
UCSRB = (1<<RXEN)|(1<<TXEN);
UDR = 0x00; // send an empty byte to indicate powerup.}
// Blink the status LEDs a little to indicate that the device has just booted.
// This is usefull to see if an error is making the device reboot when not supposed to.
// And it looks cool.
void bootmsg (void)
{
int i;
LED_PORT |= LED_GREEN;
for (i = 0; i < 2; i++)
{
// Blinky
delay_ms(1000);
LED_PORT &= ~LED_GREEN;
LED_PORT |= LED_RED;
// Blink
delay_ms(1000);
LED_PORT &= ~LED_RED;
LED_PORT |= LED_GREEN;
}
delay_ms(1000);
LED_PORT &= ~LED_GREEN;
}// Delay function used in graphical effects.
void delay_ms(uint16_t x)
{
uint8_t y, z;
for ( ; x > 0 ; x–){
for ( y = 0 ; y < 90 ; y++){
for ( z = 0 ; z < 6 ; z++){
asm volatile (“nop”);
}
}
}
}
October 22, 2010 at 8:56 am #5118dagakshayParticipanthello paras,
code you have to do it your self.
about loading bin file.,….
we always dump a ihex(intel hex file){eg: led.hex} file into a controller. and i xctaly dont know about at89c51 (atmel) . but you can do it with philips manufactured 8051 i tried it on P89CV51RD2 and the softwate you have to use is “flash magic.”
here i have given a ckt now u need to connect it with your microcontroller
remember:
connect Txd(max232) to Rxd(microntroller)
connect Rxd(max232) to Txd(microntroller)
make ground and supply common
and that IC P89CV51RD2 is pin compatible with ur c51 so no need to change ur cktry..
October 23, 2010 at 4:32 am #5120Paras WadherParticipanti knew it but problem is interfacing it with pc . i tried flash magic but it is not working in case of atmel 89c5120pc.
Thank you 4 solution.
October 23, 2010 at 11:19 am #5124dagakshayParticipantin flash magic go to option-> advance optoin-> hardware config and untick “use DTR and RST……..”
then try…….
and check your baud rate, and mx232 ckt also……
let me know wearher it works…..
-
AuthorPosts
- You must be logged in to reply to this topic.