📄 led-16sm._c
字号:
/*
Title: LED-16sm.c
Connection:
Factory fixed setting:
PORTA:
PA0-PA2 LCD control
PA3-PA7 4x7-segment display control
Drive LED group2 (the right group of LED)
PORTB:
Shared by LCD and 4x7-segment displays
output 8-bit data to LCD or 8-bit data to 4x7-segment displays
PORTC:
shared by 8-bit dipswitch and 4 x touch switches + 4 buttons
receive inputs from dipswitch, touch switches and buttons
PORTD:
Drive LED group1 (the left group of LED)
Attention:
1. J12 should be capped (connectted)
2. J5 is the Jump for LCD back light power
Operation:
See the User Mannual, which is included in CD
*/
#include <iom16v.h>
#include <macros.h>
unsigned char pattern1[]= {0x01, 0x03, 0x07, 0x0F, 0x1f, 0x3f, 0x7f, 0xff, 0x7f,
0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01};
unsigned char pattern2[]= {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x40,
0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
unsigned char pattern3[]= {0x01, 0x80, 0x02, 0x40, 0x04, 0x20, 0x08, 0x10, 0x10,
0x08, 0x20, 0x04, 0x40, 0x02, 0x80};
unsigned char pattern4[]= {0x11, 0x22, 0x44, 0x88, 0x44, 0x22, 0x11, 0x22, 0x44,
0x88, 0x44, 0x22, 0x11, 0x00, 0x00};
unsigned char pattern5[]= {0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f};
const char dig0 = 0x40, dig1 = 0x80, dig2=0x10, dig3=0x08, dot=0x20;
char segconv[]={0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f};
unsigned char BCD0, BCD1, BCD2, BCD3;
int count;
void port_init(void)
{
DDRA = 0xFF; //set PortA output
DDRB = 0xff; //set PORTB output
DDRC = 0x00; //set PORTC output
PORTC = 0xff;
DDRD = 0xFF; //set PORTD output
}
void delay(int count)
{
int i, j;
for(i=count; i>0; i--)
for(j=10; j>0; j--)
;
}
//*****************************************************************
void main(void)
{
unsigned char outa=0x00, outb=0x00, outc=0x00, outd=0x00;
int swin, swin2, led_index=0;
int j, count=0;
port_init();
PORTA=0xff;
while(1)
{
WDR(); //Watchdog reset
if(++count>30)
{
count=0;
PORTA^=0x07;
PORTB=pattern5[j++];
if(j>=8)
j=0;
}
//PORTA=swin;
swin=PINC&0x30;
swin=swin>>4;
swin2=~PINC&0x0f;
if(swin==0)
{
PORTD=pattern1[led_index];
}
else if(swin==0x01)
{
PORTD=pattern2[led_index];
}
else if(swin==0x02)
{
PORTD=pattern3[led_index];
}
else
{
PORTD=pattern4[led_index];
}
led_index++;
if(led_index>14)
led_index=0;
delay(2000+800*swin2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -