The ATmega16 MCU scientific calculator program (with addition, subtraction, multiplication and division functions) has been completed

Publisher:MysticalGlowLatest update time:2014-12-04 Source: 21icKeywords:ATmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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<  MCUCSR|= 1<DDRC=0XFF;
DDRB=0XFF;
DDRD=0XFF;
DDRA=0X0F;
while(1)
{
display(1);
diskey();
clean_junk();
}
}

 

Keywords:ATmega16 Reference address:The ATmega16 MCU scientific calculator program (with addition, subtraction, multiplication and division functions) has been completed

Previous article:ST7586S AVR MCU Driver
Next article:ATmega16 drives ds12c887 and displays on lcd1602

Recommended ReadingLatest update time:2024-11-16 03:46

Design of intelligent temperature control system based on ATmega16 and DS18B20
 0 Introduction In industrial and agricultural production and daily life, the measurement and control of temperature are becoming more and more important. Traditional temperature control systems use thermistors or thermocouples to measure temperature. However, since the analog temperature sensor outputs an analog sig
[Microcontroller]
Design of intelligent temperature control system based on ATmega16 and DS18B20
Design and implementation of voice recording and playback system based on ATMEGA16
cutting edge   The method of using magnetic tape to record, store and restore analog voice signals has a long history. Electronic products based on this method can be seen everywhere. Moreover, these products are very large and are subject to certain limitations in terms of scope of use. The single-chip voice record
[Microcontroller]
Design and implementation of voice recording and playback system based on ATMEGA16
Development of electric boiler temperature controller based on ATMEGA16
  introduction   Electric boilers can directly convert electrical energy into thermal energy. They have the advantages of high thermal efficiency, small size, no pollution, low noise, safe and reliable operation, stable heating, and a high degree of automation. They are ideal energy-saving and environmentally friend
[Microcontroller]
Development of electric boiler temperature controller based on ATMEGA16
atmega16 on-chip A/D program - CVAVR program
/***************************************************** File name : AD_on chip.c Chip type : ATmega16L Program type : Application Clock frequency : 4.000000 MHz Memory model : Small External SRAM size : 0 Data Stack size : 256 Function : Internal AD conversion, digital tube display *****************************
[Microcontroller]
Design of remote temperature difference cycle controller based on ATmega16
This design uses AVR microcontroller, RS 485 technology and NTC thermistor technology to develop the remote temperature difference cycle controller. 1 System structure and working principle The remote temperature difference cycle controller is mainly used to measure and display the water temperature of the water
[Microcontroller]
Design of remote temperature difference cycle controller based on ATmega16
ATmega16 calculator code (digital tube display)
The microcontroller source program is as follows: /**********************************************************************/     /**Counter button**              (1) (2) (3) (4)         (5) (6) (7) (8)         (9) (0) (C) (=)         (+) (-) (*) (/)                  10: Clear 11: Confirm 12: Add 13: Subtract 14: Mult
[Microcontroller]
Multi-channel hydrological parameter acquisition and wireless transmission system based on ATmega16
Introduction In order to adapt to the modernization and information requirements of flood control and water conservancy scheduling, the construction of hydrological monitoring systems has entered the digital and networked stage. In many key waters (key rivers, lakes, reservoirs, water conservancy projects, etc.), it
[Microcontroller]
Multi-channel hydrological parameter acquisition and wireless transmission system based on ATmega16
ATmega16 uses TWI module to read and write 24C02 program
/****************************************************** ******* Project name: AT_Mega16_master Creation date: 2007.10.21 Programming: Zhu Haifeng Contact: 543376422 (QQ) 13405100406 (mobile phone) AT24C02 stores a byte and reads it back for verification. If it is correct, the buzzer will sound once, and if it is i
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号