i have a HT1632C 64*16 LED Matrix
but the C program just for ATmega16L
how to run on Arduino UNO? TK~~~
/*****************************************************
Chip type : ATmega16L
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#define CSA PORTC.5
#define CSB PORTC.4
#define CSC PORTC.3
#define SCN PORTC.2
#define DAT PORTC.1
#define WR PORTC.0
#define RD PORTD.7
//*****************************************************************
void l_delay(unsigned long temp)
{
while(temp>0)
{temp--;}
}
//*****************************************************************
void delay(unsigned char temp)
{
while(temp>0)
{temp--;}
}
//*****************************************************************
void send_data_to_ht1632(unsigned int data,unsigned char cnt)
{
while(cnt > 0)
{
if(data % 2 ==0){DAT=0;}else{DAT=1;}
delay(10);
WR = 0;delay(2);
WR = 1;delay(2);
data = data >> 1;
cnt--;
}
}
//*****************************************************************
void set_address(unsigned char address)
{
switch(address)
{
case 0:CSA = 0;CSB = 0;CSC = 0;break;
case 1:CSA = 1;CSB = 0;CSC = 0;break;
case 2:CSA = 0;CSB = 1;CSC = 0;break;
case 3:CSA = 1;CSB = 1;CSC = 0;break;
}
}
//*****************************************************************
void write_ht1632_command(unsigned char address,unsigned int data)
{
set_address(address);
SCN = 0;
WR = 1;
RD = 1;
DAT = 1;
SCN = 1;
delay(10);
send_data_to_ht1632(1,3);
send_data_to_ht1632(data,9);
SCN = 0;
}
//*****************************************************************
void clear_ht1632_data(unsigned char address)
{
unsigned char i;
set_address(address);
SCN = 0;
WR = 1;
RD = 1;
DAT = 1;
SCN = 1;
delay(10);
send_data_to_ht1632(5,3);
send_data_to_ht1632(0,7);
for(i=0;i<128;i++)
{
send_data_to_ht1632(0x00,4);
}
SCN = 0;
}
//*****************************************************************
void write_ht1632_data1(unsigned char address,unsigned char temp)
{
set_address(address);
SCN = 0;
WR = 1;
RD = 1;
DAT = 1;
SCN = 1;
delay(10);
send_data_to_ht1632(5,3);
send_data_to_ht1632(0x20,7);
send_data_to_ht1632(temp,4);
SCN = 0;
}
//*****************************************************************
void write_ht1632_data2(unsigned char address,unsigned char temp)
{
unsigned char i;
set_address(address);
SCN = 0;
WR = 1;
RD = 1;
DAT = 1;
SCN = 1;
delay(10);
send_data_to_ht1632(5,3);
send_data_to_ht1632(0,7);
for(i=0;i<128;i++)
{
send_data_to_ht1632(temp,4);
}
SCN = 0;
}
//*****************************************************************
void main(void)
{
unsigned char i,j;
// Declare your local variables here
// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTA=0x00;
DDRA=0x00;
// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTB=0x00;
DDRB=0x00;
// Port C initialization
// Func7=In Func6=In Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
// State7=T State6=T State5=1 State4=1 State3=1 State2=1 State1=1 State0=1
PORTC=0x3F;
DDRC=0x3F;
// Port D initialization
// Func7=Out Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
// State7=1 State6=T State5=T State4=T State3=T State2=T State1=T State0=T
PORTD=0x80;
DDRD=0x80;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top=FFh
// OC0 output: Disconnected
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top=FFFFh
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top=FFh
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x00;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
for(i=0;i<4;i++)
{
write_ht1632_command(i,0x0018);
write_ht1632_command(i,0x0080);
write_ht1632_command(i,0x00c0);
write_ht1632_command(i,0x0014);
write_ht1632_command(i,0x00f5);
clear_ht1632_data(i);
}
while (1)
{
for(j=0;j<16;j++)
{
for(i=0;i<4;i++)
{
write_ht1632_data2(i,j);
}
l_delay(100000);
}
};
}
//End of the program