728x90

728x90

Saturday, January 24, 2026

ATMega644P Input Output Programming Example

Overview

The ATMega644P/V is equivalent to other AVR microcontrollers, ATMega16, ATMega32 and ATMega1284 etc, in footprint. However its Flash memory is 64kB with larger size in SRAM and data EEPROM. The ATMega644P could operates up to 20MHz with the supply voltage between 4.5 and 5.5VDC.

ATMega644P Input Output Programming Example
 

Using its larger memory size and high speed clock we can use this chip for graphical LCD controlling, TFT LCD controlling, Graphical User Interface (GUI) and embedded networking etc. 

Input Output Port Interfacing and Programming 

Using the Microchip Studio IDE from the device manufacture we can program a simple I/O port from scratch using a few lines of C code. 

ATMega644P Input Output Programming Example
ATMega644P 40-Pin DIP Pin Diagram

There are some paid compiler for this chip family, IAR Embedded Workbench, CodeVision AVR and MikroC Pro for AVR etc. These Compiler has a lot of built-in libraries and technical support.

PortB Blink

Since this MCU able to operates at 20MHz I tested this capability to blink the LED connects to PortB for every 1000 seconds.

  1. /*
  2. * 1-blink_port_b_20M.c
  3. *
  4. * Created: 1/25/2026 2:45:25 PM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #define F_CPU 20000000UL

  10. const uint32_t d_time=1000;

  11. int main(void)
  12. {
  13. /* Replace with your application code */
  14. DDRB=0xFF;
  15. while (1)
  16. {
  17. PORTB=0xFF;
  18. _delay_ms(d_time);
  19. PORTB=0x00;
  20. _delay_ms(d_time);
  21. }
  22. }

Proteus VSM also has a model for this chip. 

ATMega644P Input Output Programming Example
Schematic

I tested this demo program on my breadboard since my prototype board doesn't have a 20MHz clock. 

ATMega644P Input Output Programming Example

ATMega644P Input Output Programming Example

 

PortB LED Shift

I use my AVR Prototype Board to test the ATMega644P. This example chases and shifts the LED at PortB. 

  1. /*
  2. * 1-shift_port_b_16M.c
  3. *
  4. * Created: 1/24/2026 9:49:48 PM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>
  8. #include <util/delay.h>
  9. #define F_CPU 16000000UL

  10. int main(void)
  11. {
  12. /* Replace with your application code */
  13. DDRB=0xFF;
  14. while (1)
  15. {
  16. for (uint8_t i=0;i<8;i++)
  17. {
  18. PORTB=(1<<i);
  19. _delay_ms(100);
  20. }
  21. _delay_ms(2000);
  22. PORTB=0;
  23. for (uint8_t i=0;i<8;i++)
  24. {
  25. PORTB|=(1<<i);
  26. _delay_ms(100);
  27. }
  28. _delay_ms(2000);
  29. PORTB=0;
  30. for (int8_t i=7;i>=0;i--)
  31. {
  32. PORTB=(1<<i);
  33. _delay_ms(100);
  34. }
  35. _delay_ms(2000);
  36. PORTB=0;
  37. for (int8_t i=7;i>=0;i--)
  38. {
  39. PORTB|=(1<<i);
  40. _delay_ms(100);
  41. }
  42. _delay_ms(2000);
  43. PORTB=0;
  44. for (uint8_t i=0;i<0xFF;i++)
  45. {
  46. PORTB=rand();
  47. _delay_ms(100);
  48. }
  49. _delay_ms(2000);
  50. PORTB=0;
  51. }
  52. }

The schematic remains the same to about example. But it excepts that the on board clock oscillator is 16MHz.

ATMega644P Input Output Programming Example

ATMega644P Input Output Programming Example

ATMega644P Input Output Programming Example

ATMega644P Input Output Programming Example

ATMega644P Input Output Programming Example

 

I have been using PCBWay for many years now. PCBWay fabricate PCBs at low cost, fast processing time for only 24 hours, and fast delivery time using any carrier options. This double side 10cmx10cm can be fabricate at only 5USD for 5 to 10pcs by PCBWay. It's a standard PCB with silk screen and solder mask.

A DIY dsPIC30F2010 and dsPIC30F1010 Prototype Board with Programmer
10 PCBs for only 5USD
 

For different size of PCB we can instantly quote on PCBWay website using a zip PCB Gerber file without account.

A DIY dsPIC30F2010 and dsPIC30F1010 Prototype Board with Programmer
PCBWay Instant Quote


I tested this demo example on my AVR Prototype Board.

Switches and LED

There are three push buttons and 8 LED on the prototype board. So I will the its input and output pins.

  1. /*
  2. * 2-InputOutput_2_16M.c
  3. *
  4. * Created: 1/25/2026 9:55:36 AM
  5. * Author : Admin
  6. */

  7. #include <avr/io.h>


  8. int main(void)
  9. {
  10. /* Replace with your application code */
  11. DDRB=0xFF;
  12. DDRB&=~(1<<2);
  13. DDRD=0x00;
  14. PINB=(1<<2);
  15. PIND=(1<<2)|(1<<3);
  16. uint8_t tmp1=0,tmp2;
  17. while (1)
  18. {
  19. tmp1=(PINB&0x04);
  20. tmp1<<=3;
  21. tmp2=(PIND&0x04)|(PIND&0x08);
  22. tmp2<<=4;
  23. PORTB=tmp1|tmp2;
  24. }
  25. }


We can simulate this program in Proteus VSM without testing on Prototype Board. 

ATMega644P Input Output Programming Example
 

Six Digits 7-Segment Display

There is six-digit common cathode multiplexing display. The ATMega644P drives each digits for 5ms repeatedly to make it readable.

  1. /*
  2. * 3-6_digits_swap.c
  3. *
  4. * Created: 1/25/2026 12:16:51 PM
  5. * Author : Admin
  6. */
  7. /************************************************************************/
  8. /* This Sample Program is designed for the ATMega16 Development Board */
  9. /************************************************************************/
  10. #include <avr/io.h>
  11. #include <util/delay.h>
  12. #define F_CPU 16000000UL

  13. const uint8_t cc_7[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,
  14. 0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
  15. const uint16_t d_time=5;

  16. int main(void)
  17. {
  18. /* Replace with your application code */
  19. DDRB=0xFF;
  20. DDRC=0xFF;
  21. while (1)
  22. {
  23. PORTC=0;
  24. PORTB=cc_7[0];
  25. PORTC=0x20;
  26. _delay_ms(d_time);
  27. PORTC=0;
  28. PORTB=cc_7[1];
  29. PORTC=0x40;
  30. _delay_ms(d_time);
  31. PORTC=0;
  32. PORTB=cc_7[2];
  33. PORTC=0x80;
  34. _delay_ms(d_time);
  35. PORTC=0;
  36. PORTB=cc_7[3];
  37. PORTC=0x04;
  38. _delay_ms(d_time);
  39. PORTC=0;
  40. PORTB=cc_7[4];
  41. PORTC=0x08;
  42. _delay_ms(d_time);
  43. PORTC=0;
  44. PORTB=cc_7[5];
  45. PORTC=0x10;
  46. _delay_ms(d_time);
  47. }
  48. }


I tested it both in software simulator and hardware.

ATMega644P Input Output Programming Example
 

I swapped each displays in Proteus VSM to fit the on-board display. 

You can check the detail of this prototype board in pcbway that I shared many years now.































No comments:

Post a Comment

320x50

Search This Blog

tyro-728x90