Chia sẻ GIAO TIẾP MODULE P10 RED + AT328P ( CoDE C )

ledacdam

Kỹ sư
#1
Code c giao tiếp module P10 32x16 red ngoài trời với Atmega328P
Code :
Mã:
#include <mega328p.h>  // Sử dụng chip Atmega328
#include <delay.h>     // Thư viện tạo trễ

#define OE             PORTD.3 // Chân on/off 138
#define A0             PORTD.4 // Đầu vào A( 138)
#define B0             PORTD.5 // Đầu vào B( 138)
#define CL             PORTD.6 // Chân clock HC595
#define ST             PORTD.7 // Chân chốt dữ liệu HC595
#define DA             PORTB.0 // Chân xuất data HC595

unsigned char r = 0;  // biến quét led 1/4
unsigned char RAM_P10[64][4] ; // Mảng lưu dữ liệu led
flash unsigned char Font16[][32] ={   // Font 16x16
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3B,0x3B,0x3B,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x60,0x7E,0x3E,0x0E,0x00,0x60,0x7E,0x3E,0x0E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x18,0x18,0xFE,0xFE,0xFE,0x18,0x18,0x18,0x18,0xFE,0xFE,0xFE,0x18,0x18,0x00,0x00,0x0C,0x0C,0x3F,0x3F,0x3F,0x0C,0x0C,0x0C,0x0C,0x3F,0x3F,0x3F,0x0C,0x0C,0x00},  // 0x    ''
{0x00,0x30,0x78,0x78,0xFC,0xCC,0xCC,0xFE,0xFE,0xFE,0xCC,0xCC,0x8C,0x8C,0x0C,0x00,0x00,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x3F,0x3F,0x0C,0x0C,0x0F,0x07,0x03,0x00},  // 0x    ''
{0x00,0x0C,0x1E,0x1E,0x0C,0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1E,0x0E,0x06,0x00,0x00,0x00,0x18,0x1C,0x1E,0x0F,0x07,0x03,0x01,0x00,0x0C,0x1E,0x1E,0x0C,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x98,0xBC,0xFE,0x66,0x66,0xFE,0xBC,0x98,0x00,0x00,0x80,0x80,0x00,0x00,0x06,0x0F,0x1F,0x1F,0x19,0x18,0x18,0x19,0x1F,0x1F,0x0F,0x0F,0x1B,0x19,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x38,0x3C,0x1C,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF8,0xFC,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0x1F,0x3F,0x30,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0xFC,0xF8,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x3F,0x1F,0x0F,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x60,0xF8,0xF8,0xFC,0x9C,0x0E,0x0E,0x9C,0xFC,0xF8,0xF8,0x60,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x03,0x03,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x3F,0x3F,0x03,0x03,0x03,0x03,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0xFC,0x7C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x3C,0x3C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1E,0x0E,0x00,0x00,0x60,0x70,0x78,0x3C,0x1E,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0xE0,0xF8,0xFC,0xFC,0x0E,0x06,0x06,0x06,0x06,0x0E,0xFC,0xFC,0xF8,0xE0,0x00,0x00,0x07,0x1F,0x3F,0x3F,0x70,0x60,0x60,0x60,0x60,0x70,0x3F,0x3F,0x1F,0x07,0x00},  // 0x    ''
{0x00,0x00,0x18,0x18,0x18,0x1C,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x7F,0x7F,0x7F,0x7F,0x60,0x60,0x60,0x60,0x60,0x00},  // 0x    ''
{0x00,0x10,0x1C,0x1C,0x1E,0x0E,0x06,0x06,0x06,0x06,0x8E,0xFE,0xFC,0xFC,0x78,0x00,0x00,0x70,0x78,0x78,0x7C,0x7C,0x6E,0x6E,0x67,0x67,0x63,0x63,0x61,0x60,0x60,0x00},  // 0x    ''
{0x00,0x10,0x1C,0x1C,0x1E,0x0E,0x06,0x86,0x86,0x86,0xCE,0xFE,0xFC,0x7C,0x30,0x00,0x00,0x08,0x38,0x38,0x78,0x70,0x60,0x61,0x61,0x61,0x73,0x7F,0x3F,0x3F,0x0E,0x00},  // 0x    ''
{0x00,0x00,0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1E,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x0F,0x0F,0x0F,0x0D,0x0C,0x0C,0x0C,0x0C,0x7F,0x7F,0x7F,0x7F,0x0C,0x0C,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xFE,0xC6,0x66,0x66,0x66,0x66,0xE6,0xE6,0xC6,0xC6,0x00,0x00,0x00,0x11,0x31,0x31,0x71,0x70,0x60,0x60,0x60,0x60,0x70,0x7F,0x3F,0x3F,0x0F,0x00},  // 0x    ''
{0x00,0xF0,0xFC,0xFC,0xFE,0x8E,0xC6,0xC6,0xC6,0xC6,0xCE,0xDE,0x9C,0x9C,0x10,0x00,0x00,0x0F,0x3F,0x3F,0x7F,0x71,0x60,0x60,0x60,0x60,0x71,0x7F,0x3F,0x3F,0x0F,0x00},  // 0x    ''
{0x00,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x0E,0x8E,0xCE,0xFE,0xFE,0x7E,0x3E,0x00,0x00,0x00,0x40,0x60,0x70,0x78,0x3C,0x1E,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x30,0x7C,0x7C,0xFE,0xCE,0x86,0x86,0x86,0x86,0xCE,0xFE,0x7C,0x7C,0x30,0x00,0x00,0x0E,0x3F,0x3F,0x7F,0x73,0x61,0x61,0x61,0x61,0x73,0x7F,0x3F,0x3F,0x0E,0x00},  // 0x    ''
{0x00,0xF0,0xFC,0xFC,0xFE,0x8E,0x06,0x06,0x06,0x06,0x8E,0xFE,0xFC,0xFC,0xF0,0x00,0x00,0x08,0x39,0x39,0x7B,0x73,0x63,0x63,0x63,0x63,0x71,0x7F,0x3F,0x3F,0x0F,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x18,0x3C,0x3C,0x18,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xE0,0x7C,0x3C,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0x70,0x38,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x18,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x38,0x3C,0x3E,0x0E,0x06,0x06,0x06,0x06,0x06,0x06,0x8E,0xFE,0xFC,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x34,0x36,0x37,0x03,0x01,0x00,0x00,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x0E,0xC6,0xE6,0x36,0x36,0xE6,0xC6,0x0E,0xFC,0xFC,0xF8,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x31,0x33,0x33,0x31,0x33,0x33,0x03,0x03,0x03,0x03,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x8E,0x86,0x86,0x86,0x86,0x86,0x86,0x8E,0xFC,0xFC,0xF8,0x00,0x00,0x3F,0x3F,0x3F,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xEE,0x7C,0x7C,0x38,0x00,0x00,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x1F,0x0E,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x0E,0x06,0x06,0x06,0x06,0x06,0x06,0x0E,0x3C,0x3C,0x38,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1E,0x1E,0x0E,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x0E,0xFC,0xFC,0xF8,0x00,0x00,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x06,0x06,0x06,0x00,0x00,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0x06,0x06,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x0E,0x06,0x06,0x06,0x06,0x06,0x06,0x0E,0x3C,0x3C,0x38,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x33,0x33,0x33,0x33,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xFE,0xFE,0xFE,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0x00,0x06,0x06,0x06,0x06,0x06,0xFE,0xFE,0xFE,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0xFE,0xFE,0xFE,0x00,0x00,0x0E,0x1E,0x1E,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0xC0,0xC0,0xC0,0xC0,0xE0,0xF0,0x38,0x1C,0x0E,0x06,0x02,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFC,0x38,0x70,0xE0,0xC0,0xC0,0xE0,0x70,0x38,0xFC,0xFE,0xFE,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x01,0x01,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFC,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0xFE,0xFE,0xFE,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x0E,0x06,0x06,0x06,0x06,0x06,0x06,0x0E,0xFC,0xFC,0xF8,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x8E,0xFC,0xFC,0xF8,0x00,0x00,0x3F,0x3F,0x3F,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x01,0x01,0x00,0x00},  // 0x    ''
{0x00,0xF8,0xFC,0xFC,0x0E,0x06,0x06,0x06,0x06,0x06,0x06,0x0E,0xFC,0xFC,0xF8,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0xFC,0xFC,0xFC,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x8E,0xFC,0xFC,0xF8,0x00,0x00,0x3F,0x3F,0x3F,0x03,0x03,0x03,0x07,0x0F,0x0F,0x1F,0x1B,0x39,0x31,0x30,0x00},  // 0x    ''
{0x00,0x38,0x7C,0x7C,0xEE,0xC6,0xC6,0xC6,0xC6,0xC6,0xC6,0xCE,0x9C,0x9C,0x18,0x00,0x00,0x0C,0x1C,0x1C,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x39,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0x00,0x06,0x06,0x06,0x06,0x06,0xFE,0xFE,0xFE,0x06,0x06,0x06,0x06,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x38,0x1C,0x0E,0x07,0x03,0x01,0x00,0x00},  // 0x    ''
{0x00,0xFE,0xFE,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0xFE,0xFE,0x00,0x00,0x0F,0x1F,0x3F,0x38,0x1C,0x0E,0x07,0x07,0x0E,0x1C,0x38,0x3F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0x06,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x06,0x00,0x00,0x30,0x38,0x1C,0x0E,0x07,0x03,0x01,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00},  // 0x    ''
{0x00,0x06,0x0E,0x1C,0x38,0x70,0xE0,0xC0,0xC0,0xE0,0x70,0x38,0x1C,0x0E,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x86,0xC6,0xE6,0x76,0x3E,0x1E,0x0E,0x06,0x00,0x00,0x30,0x30,0x38,0x3C,0x3E,0x37,0x33,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x0C,0x1C,0x38,0x70,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x03,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x60,0x60,0x18,0x18,0xFE,0xFE,0xFE,0x18,0x18,0x60,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x06,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x0C,0x1E,0x1E,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xFF,0xFF,0xFF,0x60,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x3F,0x3F,0x3F,0x18,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1C,0x1C,0x0C,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0x60,0xFF,0xFF,0xFF,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0xE0,0xE0,0xC0,0x00,0x00,0x0F,0x1F,0x1F,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x31,0x30,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x30,0x30,0x30,0xFC,0xFE,0xFE,0x37,0x33,0x33,0x03,0x03,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0x60,0xF0,0xF0,0xF0,0x00,0x00,0x03,0x07,0xC7,0xCE,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xE6,0x7F,0x7F,0x3F,0x00},  // 0x    ''
{0x00,0xFF,0xFF,0xFF,0x60,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x30,0x30,0x30,0xF7,0xF7,0xF7,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF7,0xF7,0xF7,0x00,0x00,0x38,0x78,0x78,0xE0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xE0,0x7F,0x7F,0x3F,0x00},  // 0x    ''
{0x00,0xFF,0xFF,0xFF,0x00,0x00,0x80,0xC0,0xE0,0xF0,0x38,0x1C,0x0C,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x0E,0x07,0x03,0x01,0x01,0x03,0x07,0x0E,0x1C,0x38,0x30,0x00},  // 0x    ''
{0x00,0x00,0x00,0x00,0x00,0x03,0x03,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x30,0x30,0x3F,0x3F,0x3F,0x30,0x30,0x30,0x30,0x00,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x30,0x30,0x60,0xE0,0xC0,0xE0,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x60,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x38,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x60,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0xFF,0xFF,0xFF,0x06,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0E,0x07,0x07,0x03,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x70,0x30,0x30,0x30,0x30,0x30,0x30,0x60,0xF0,0xF0,0xF0,0x00,0x00,0x03,0x07,0x07,0x0E,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x06,0xFF,0xFF,0xFF,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x60,0x30,0x30,0x30,0x30,0x30,0x30,0x70,0xE0,0xE0,0xC0,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00},  // 0x    ''
{0x00,0xC0,0xE0,0xE0,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x31,0x31,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x1E,0x1E,0x0C,0x00},  // 0x    ''
{0x00,0x00,0x30,0x30,0x30,0x30,0x30,0xFF,0xFF,0xFF,0x30,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x3F,0x3F,0x00,0x00,0x00,0x00,0x00,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x30,0x30,0x30,0x30,0x18,0x3F,0x3F,0x3F,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x01,0x07,0x1F,0x3E,0x38,0x30,0x30,0x38,0x3E,0x1F,0x07,0x01,0x00,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x0F,0x1F,0x1F,0x38,0x30,0x30,0x1F,0x0F,0x1F,0x30,0x30,0x1F,0x1F,0x0F,0x00},  // 0x    ''
{0x00,0x70,0x70,0xE0,0xE0,0xC0,0xC0,0x80,0x80,0xC0,0xC0,0xE0,0xE0,0x70,0x70,0x00,0x00,0x38,0x38,0x1C,0x1C,0x0F,0x0F,0x07,0x07,0x0F,0x0F,0x1C,0x1C,0x38,0x38,0x00},  // 0x    ''
{0x00,0xF0,0xF0,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF0,0xF0,0xF0,0x00,0x00,0x03,0x07,0xC7,0xCE,0xCC,0xCC,0xCC,0xCC,0xCC,0xCC,0xE6,0x7F,0x7F,0x3F,0x00},  // 0x    ''
{0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0xB0,0xB0,0xF0,0xF0,0x70,0x30,0x00,0x00,0x30,0x38,0x3C,0x3C,0x36,0x36,0x33,0x33,0x31,0x31,0x30,0x30,0x30,0x30,0x00},  // 0x    ''
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void nop(unsigned char t)  
{
  for(;t>0;t--)
  {
   ;
  }
} //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void HC595(unsigned char byte) // Hàm gửi 1 byte dữ liệu vào HC595
    {                            
    unsigned char i;
    for(i=0;i<8;i++)
                         {
                         DA=(byte & 0x80);
                         CL=1;
                         byte<<=1;
                         CL=0;
                         }  
    }  
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
interrupt [TIM0_OVF] void timer0_ovf_isr(void)   // Dùng timer 0 để quét led
    {
    unsigned char i;
    TCCR0B=0x00;
    r++;
    if(r==4) { r=0; }
    for(i=0;i<16;i++) // Đẩy dữ liệu vào
                    {
                    HC595(~RAM_P10[48+i][r]);
                    HC595(~RAM_P10[32+i][r]);
                    HC595(~RAM_P10[16+i][r]);
                    HC595(~RAM_P10[i][r]);
                    }
    ST = 0; // Tạo xung chốt
    ST = 1;      
    switch(r) // Điều khiển đầu vào 138 để bặt lần lượt các hàng led
                    {
                    case 0: A0=0;B0=0;OE=1; break;
                    case 1: A0=1;B0=0;OE=1; break;
                    case 2: A0=0;B0=1;OE=1; break;
                    case 3: A0=1;B0=1;OE=1; break;
                    }
    nop(200);
    OE = 0;
    TCCR0B=0x03;
    }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void Xoa()  // Hàm xóa trắng module
    {
    unsigned char i =0,j = 0;
    for(i=0;i<4;i++)
                   {
                   for(j=0;j<64;j++)
                                   {
                                   RAM_P10[j][i]=0x00;
                                   }
                   }
    }      
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void Pixel(unsigned char x,unsigned char y) // In 1 điểm ảnh ở tọa độ xy
    {
    unsigned char  y1=0,x1=0;
    unsigned char  y2=0,x2=0;
    unsigned char  temp=0;
    y1 = y%4;
    y2 = y/4;
    x1 = x%8;  
    x2 = x/8;
    temp=RAM_P10[(y2*16)+x2][y1];
             RAM_P10[(y2*16)+x2][y1] = (temp | (128>>x1));
    }    
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
unsigned int Xu_ly_hang(unsigned int hang, unsigned int B_dau, unsigned int K_thuc, unsigned char x)
    { // Cuộn 1 hàng
    // hang : Điểm bắt đầu
    // B_dau : Điểm bắt đầu trên module
    // K_thuc : Điểm kết thúc trên module ( VD : Dùng 4 module -> Giá trị B_dau,K_thuc lần lượt = 0,15
    // x : Màu ( x = 1-> led sáng,=0-> led tối
    unsigned char  i=0;
    unsigned char  y1=hang%4;
    unsigned char  y2=(hang/4)*16;
    unsigned char  Luu, Tam;
    x=1-x;
    Luu=(RAM_P10[y2+B_dau][y1]/128)&0x01;
    for(i=B_dau;i<K_thuc+1;i++)
             {
             if(i<15)
                      {
                      Tam=(RAM_P10[y2+(i+1)][y1]/128)&0x01;                      
                      RAM_P10[y2+i][y1] = RAM_P10[y2+i][y1]<<1;              
                      RAM_P10[y2+i][y1] = (unsigned int)RAM_P10[y2+i][y1]|Tam;    
                      }
             else
                      {
                      RAM_P10[y2+i][y1] = RAM_P10[y2+i][y1]<<1;              
                      }
             }
    if(x)
             {                                                        
             RAM_P10[((y2)+K_thuc)][y1] = (int)RAM_P10[((y2)+K_thuc)][y1]|0x01;
             }
    else
             {
             RAM_P10[((y2)+K_thuc)][y1] = (int)RAM_P10[((y2)+K_thuc)][y1]&0xFE;
             }
    return Luu;
    }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void Chay_chu_16(unsigned char B_dau, unsigned char K_thuc,unsigned char* textptr)
    {
     // Chạy 1 dòng text trong khoảng từ B_dau -> K_thuc trên module
     // VD : Chay_chu_16(x,y,"Text .....");
     // Nếu y = 3 : Text sẽ chạy trong khỏang module 1
     // Nếu y = 7 : Text sẽ chạy trong khỏang module 1&2
     // Nếu y = 11 : Text sẽ chạy trong khỏang module 1-3
     // Nếu y = 15 : Text sẽ chạy trong khỏang module 1-4
     // ... Nếu muốn chạy module thứ 2 và 3 -> Chay_chu_16(3,11,"Text .....");
    unsigned char a=0,b=0;
    while(*textptr!='\0')
              {
              for(b=0;b<16;b++)
                              {
                              for(a=0;a<8;a++)
                                             {
                                             Xu_ly_hang(a,B_dau,K_thuc,1-((Font16[*textptr-32][b])>>a)&0x01);
                                             }
                              for(a=0;a<8;a++)
                                             {
                                             Xu_ly_hang(8+a,B_dau,K_thuc,1-((Font16[*textptr-32][b+16])>>a)&0x01);
                                             }
                              }
              textptr++;
              }
    }
   
void Test() //Chạy 1 viền vòng tròn 4 tấm
    {
    signed int x;
    for(x=0;x<128;x++)
              {
              Pixel(x,0);
              delay_ms(10);
              }
    for(x=0;x<16;x++)
              {
              Pixel(127,x);
              delay_ms(10);
              }
    for(x=128;x>-1;x--)
              {
              Pixel(x,15);
              delay_ms(10);
              }
    for(x=15;x>-1;x--)
              {
              Pixel(0,x);
              delay_ms(10);
              }
    delay_ms(1000);
    }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
void main()
    {
    PORTB=0xFF;
    PORTC=0xFF;
    PORTD=0xFF;
    DDRB=0xFF;
    DDRC=0xFF;
    DDRD=0xFF;
    BUZZER = 0;
    MCUCR=0x00;
    TWBR=12;          
    TCCR0B=0x03;
    TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (1<<TOIE0);
    Xoa();  
    #asm("sei")
    Test();
    while(1)
         {
         Chay_chu_16(0,15,"HAPPY NEW YEAR 2018        ");
         }
    }
 

Đính kèm

Sửa lần cuối:

Quảng cáo Google