8x8 LED Matrix Control with AVR Microcontroller
subratasarkar20
c_cpp
10 months ago
1.6 kB
7
Indexable
#define F_CPU 1000000UL #include <avr/io.h> #include <util/delay.h> #define columnDDR DDRB // Setting up Data Direction Register for column #define columnPort PORTB // Setting up PORT for column #define rowDDR DDRD // Setting up Data Direction Register for row #define rowPort PORTD // Setting up PORT for row // #define column_Address 2 // Define COLUMN address of LED matrix // #define row_Address 1 // Define ROW address of LED matrix #define LED_State 1 void LEDMatrix_Init (void); // function for initialization of LED matrix void LEDMatrix_SetPixel (int row, int column, int state); // function for turning ON the LED matrix int main (void) { LEDMatrix_Init (); while (1) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { LEDMatrix_SetPixel (i , j, 1); /*_delay_ms(1);*/ } } } } void LEDMatrix_Init (void) { columnDDR = 0XFF; // Set the column PINS as output columnPort = 0x00; // Initially clear all the PINs because it will connected to VCC or HIGH rowDDR = 0xFF; // Set the row pins as output rowPort = 0xFF; // Initially set all the PINs because it will be connected to GND or LOW } void LEDMatrix_SetPixel (int column, int row, int state) { LEDMatrix_Init (); if(state == 0) { columnPort &= ~(1 << column); // Set the column port or set as HIGH rowPort &= ~ (1 << row); // Reset the row port or set as LOW } else { columnPort |= (1 << column); // Set the column port or set as HIGH rowPort &= ~ (1 << row); // Reset the row port or set as LOW } }
Editor is loading...
Leave a Comment