using atmega32A c code to add, sub, mul and divide.

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello, 

can I use atmega32 c code in atmel studio to add, subtract, multiply and divide 4-bit number with another 4-bit number and display the result on 7-segment display ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Just use unit8_t then mask to 4 bits.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use an Intel 4004 emulator -- that is a 4-bit architecture.

https://hackaday.io/project/2557...

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

learner_AVR wrote:
4-bit number

So your range of inputs is 0-15, or did you mean BCD values 0-9?
jim

 

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

I wondered about 4 bit multiplication. There aren't that many combinations of 4 bits as multiplicands that won't simply overflow a 4 bit result ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

clawson wrote:
I wondered about 4 bit multiplication.

I think the due date for the assignment may have passed.

 

Is OP perhaps doing a BCD library?  Where is that DAA instruction?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Mon. Dec 16, 2019 - 01:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

4x4 bit certainly fits in 8bit.

AVR does 8bit hw efficiently.Atmega32 has hw multiplication but not division.The compiler will take care anyway

uint8_t x,y;
uint8_t result;
result=x*y;//multiply
result=x/y;//division

Also to display connect them to the same port if possible and create a mem vector that stores the bit combination in a uint8_t for the respective port.

like:

v[0] has the combination for '0'

v[1] for '1'

.............

where each bit turns on a pin in a port.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
I think the due date for the assignment may have passed

A common assignment used to be to emulate a simple 4-function ( + - * / ) calculator on an 8051 + keypad + 7-Seg display.

 

Maybe they've "upgraded" to AVR ... ?

 

cheeky

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...