Supports unsigned long integer value calculations up to eight bits, and signed operations and other calculation functions will be added later.
#include
#include
//#include
#define uchar unsigned char
#define uint unsigned int
#define ulong unsigned long
#define EA SREG|=BIT(7)
uchar temp ,old,key_turn,flag=0;
ulong datA=0,datB=0;
const uchar wela[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
const uchar tab[11]={ 0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x00};
extern uchar dat[8]={0,0,0,0,0,0,0,0};
extern uchar dat_right[]={0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a,0x0a};
void delay( uint z)
{
while(z--);
}
void display(uchar z)
{
uchar i;
while(z--)
for(i=0;i<8;i++)
{
PORTB=wela[i];
PORTD= tab[dat_right[i]];
delay(30);
PORTB=0XFF;
}
}
void clean_junk()
{
uchar i,p=0;
for(i=0;i<8;i++)
{
dat_right[i]=0x0a;
}
for(i=0;i<8;i++)
{
if(dat[ i]>0)p=1;
if(p)dat_right[i]=dat[i];
}
}
void delete()
{
uchar i;
for(i=0;i<8;i++)
{
dat[i] =0;
}
clean_junk();
}
void disan_he()
{
ulong i;
i=dat[0]*1e7+dat[1]*1e6+dat[2]*1e5+dat[3]*1e4+dat[4 ]*1e3+dat[5]*1e2+dat[6]*1e1+dat[7];
if(flag)datB=i;
else datA=i;
flag=1;
delete();
}
void disan_fen()
{
dat[0]=datA/1e7;
dat[1]=datA%10000000/1000000;
dat[2]=datA%1000000/100000;
dat[3]= datA%100000/10000;
dat[4]=datA%10000/1000;
dat[5]=datA%1000/100;
dat[6]=datA%100/10;
dat[7]=datA%10;
flag= 0;
}
void move()
{
uchar i;
if(temp>0&temp<0x0b)
{
for(i=0;i<8;i++)
{
dat[i]=dat[i+1];
}
if(temp==0x0a ){dat[0]=0;temp=0;}
dat[7]=temp;temp=0;
}
}
void clean()
{
uchar i;
flag=0;
for(i=0;i<8;i++ )
{
dat[i]=0;
}
temp=0;
old=0;
datA=0;
datB=0;
}
void disan()
{
if(temp>0&temp<0x11)switch(temp)
{
case 0x0e:clean( );break;
case 0x0b:old=temp;temp=0;disan_he();break;
case 0x0c:old=temp;temp=0;disan_he();break;
case 0x0d:old=temp;temp=0;disan_he();break;
case 0x10:old=temp;temp=0;disan_he();break;
case 0x0f:switch(old)
{
case 0x0b:if(flag)disan_he( );datA=datA/datB;old=0;temp=0;disan_fen();break;
case 0x0c:if(flag)disan_he();datA=datA*datB;old=0;temp=0;disan_fen() ;break;
case 0x0d:if(flag)disan_he();datA=datA-datB;old=0;temp=0;disan_fen();break;
case 0x10:if(flag)disan_he();datA=datA+datB ;old=0;temp=0;disan_fen();break;
default:temp=0;old=0;break;
}break;
default:move();temp=0;break;
}
// disan_fen();delete();
}
void diskey()
{
uchar i,n;
const uchar code[]={0xFE,0xFD,0xFB,0xF7};
if(temp==0x00)for(i=0;i<4;i++)
{
PORTA=code [i];
temp=PINA;
if(~temp&0xf0)i=6;
while(~PINA&0xf0)display(1);
PORTA=0xff;
}
if(temp>0x10)switch(temp)
{
case 0xEE:temp=0x07; break;
case 0xDE:temp=0x08;break;
case 0xBE:temp=0x09;break;
case 0x7E:temp=0x0b;break;
////////////////////// ////
case 0xED:temp=0x04;break;
case 0xDD:temp=0x05;break;
case 0xBD:temp=0x06;break;
case 0x7D:temp=0x0c;break;
///////////////////////// //
case 0xEB:temp=0x01;break;
case 0xDB:temp=0x02;break;
case 0xBB:temp=0x03;break;
case 0x7B:temp=0x0d;break;
//////////// ////////////
case 0xE7:temp=0x0e;break;
case 0xD7:temp=0x0a;break;
case 0xB7:temp=0x0f;break;
case 0x77:temp=0x10;break;
// /////////////////////////
default:temp=0x00;break;
}
disan();
}
void main()
{
MCUCSR|= 1<
DDRB=0XFF;
DDRD=0XFF;
DDRA=0X0F;
while(1)
{
display(1);
diskey();
clean_junk();
}
}
Previous article:ST7586S AVR MCU Driver
Next article:ATmega16 drives ds12c887 and displays on lcd1602
Recommended ReadingLatest update time:2024-11-16 03:46
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- C2000 CLA FAQ: Development tools, debugging, etc.
- Introduction to Microcontroller (MCU) Architecture
- Academician Li Guojie: 13 judgments on the nature and value of artificial intelligence, beware of repeating the same mistakes!
- Pull-down resistor
- Purgatory Legend-Binary to BCD Battle
- 2020 Medtec China Exhibition and International Medical Device Design and Manufacturing Technology Exhibition invites you to participate!
- Share the problem of using LM3409
- EEWORLD University - Designing wide input DC/DC converters for solar inverter applications
- UCC28056 PFC Evaluation Board
- In low temperature environment, the battery level of the device is displayed as 90%, but when it is brought to normal temperature, the battery level drops rapidly until it shuts down. What is the principle behind this?