📄 segdisp-16sm.c
字号:
/*
Title: SegDisp-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:
1. 4 x 7-segment displays show the inputs to PORTC in Binary
*/
#include <iom16v.h>
#include <macros.h>
unsigned char pattern[]={0x01, 0x03, 0x07, 0x0F, 0x1f, 0x3f, 0x7f, 0xff, 0x7f,
0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01};
unsigned char rowused[]={0x01, 0x02, 0x10, 0x08, 0x04, 0x20, 0x40, 0x80};
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 BinToBCD(int data)
{
BCD0=0;
BCD1=0;
BCD2=0;
BCD3=0;
if(data>=10000)
data=0;
if(data>=1000)
{
BCD3=data/1000;
data=data%1000;
}
if(data>=100)
{
BCD2=data/100;
data=data%100;
}
if(data>=10)
{
BCD1=data/10;
data=data%10;
}
BCD0=data;
}
void dispseg(void)
{
PORTB=~segconv[BCD0];
PORTA=dig0;
delay(20);
PORTB=~segconv[BCD1];
PORTA=dig1;
delay(20);
PORTB=~segconv[BCD2];
PORTA=dig2;
delay(20);
PORTB=~segconv[BCD3];
PORTA=dig3;
delay(20);
}
void dot_on(void)
{
PORTB=~0x80;
PORTA=dot;
delay(20);
}
//*****************************************************************
void main(void)
{
unsigned char outa=0x00, outb=0x00, outc=0x00, outd=0x00;
unsigned char dswin;
port_init();
while(1)
{
WDR(); //Watchdog reset
dswin=PINC;
BinToBCD(dswin);
dispseg();
dot_on();
PORTD=0x55;
delay(5);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -