Menu

Adskeeper - header widge

728x90

468x60

Navbar

AdsKeeper - IAB Display Standard Ad Unit

Sunday, May 24, 2020

Driving a multiplexing SSD display and keys scanning using timer 0 interrupt of ATMega32

In the previous post I use timer 0 interrupt to create a timing delay. Now I use this method again to schedule two tasks, multiplexed SSD and key scanning.

The program process is describing as follow:
  1. A four-digit multiplexed SSD display activated by timer 0 interrupt. Each digit is activated within 5 milli seconds period. The period created by timer 0 ISR.
  2. Three keys, up counter , reset counter and down counter are activated for every 200 milli seconds. Again this 150 milli seconds period generated by timer 0 ISR.
I do not describe the core programming of timer 0 here since I have done it in the previous post.

Driving a multiplexing SSD display and keys scanning using timer 0 interrupt of ATMega32
Schematic diagram.
ATMega32 fed from a 4 MHz clock source.
PD0 is an up counter. PD1 is a reset counter. PD2 is a down counter.
Each button becomes active after 200 milli seconds.
The four-digit multiplexed SSD is a timer interrupt driven display.
Each digit activated for every 5 milli seconds.

The C source codes is here.

#include <avr/io.h>
#include "avr/interrupt.h"
#define upButton ((PIND&0x01)==0)
#define resetButton ((PIND&0x02)==0)
#define downButton  ((PIND&0x04)==0)
/*System clock ticks for SSDs*/
unsigned char ssdTick=0,digit=0;
/*System clock ticks for keys*/
unsigned int found1=0,found2=0,found3=0;
unsigned int pressedCounter=1234;
void display(void){
 unsigned char patterns[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,
 0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
 switch(digit){
  case 1:
   PORTD=0x07;
   PORTC=patterns[pressedCounter/1000];
   PORTD=0x17;
   break;
  case 2:
   PORTD=0x07;
   PORTC=patterns[(pressedCounter%1000)/100];
   PORTD=0x27;
   break;
  case 3:
   PORTD=0x07;
   PORTC=patterns[(pressedCounter%100)/10];
   PORTD=0x47;
   break;
  case 4:
   PORTD=0x07;
   PORTC=patterns[pressedCounter%10];
   PORTD=0x87;
   break;
  case 5:
   digit=0;
   break;
 }
}
void buttonScan(){
 if (found1>=200)
 {
  if(upButton)
   if(pressedCounter<10000)
    pressedCounter+=1;
  found1=0;
 }
 if (found2>=200)
 {
  if(resetButton)
   pressedCounter=0;
  found2=0;
 }
 if (found3>=200)
 {
  if(downButton)
   if(pressedCounter>0)
    pressedCounter-=1;
  found3=0;
 }
}
int main(void)
{
 //Set PortC to Output
 DDRC=0xFF;
 //Clear PortC
 PORTC=0x00;
 DDRD=0xF8;
 PORTD=0x07;
 PORTC=0x00;
 //Set 1:256 prescaler
 TCCR0=0x04;
 //Clear overflow flag
 TIFR=0x01;
 //Enable Timer 0 interrupt
 TIMSK=0x01;
 //set global interrupt
 sei();
 while (1)
 {
  display();
  buttonScan();
 }
}
ISR(TIMER0_OVF_vect){
  //Load -16 to make 1 mS interrupt time
 TCNT0=-16;
 ssdTick+=1;
 //increase counters for SSD
 if(ssdTick>=5){
  digit+=1;
  ssdTick=0;
 }
 found3+=1;
 found2+=1;
 found1+=1;
 //Clear Flag
 TIFR=0x01;
}
Back to main tutorial page ATMega32 tutorials in C with Atmel Studio 7.





No comments:

Post a Comment

Adskeep- Standard Ads

336x280

Search This Blog

AdsKeeper - 2091654

Labels

23K256 (1) 24C16B (2) 25AA010A (2) 8051 (7) 93AA46B (1) ADC (34) Analog Comparator (1) Arduino (16) ARM (15) AT89C52 (7) ATMega32 (59) ATMega644P (27) AVR (88) AVR PCB (2) Bootloader (1) CCS PICC (31) Change Notify Interrupt (CNI) (2) DAC (2) DHT11 (4) Display (137) Distance Sensor (3) dot matrix (1) ds1307 (10) DS18B20 (5) ds3231 (1) ds3232 (2) dsPIC (5) dsPIC30F1010 (3) dsPIC30F2010 (5) EEPROM (5) Environment Sensor (5) ESP32 (1) esp8266 (1) Graphical LCD (3) I2C (38) ILI9341 (1) Input/Output (78) Interrupt (22) IoT PCB (1) Keil (5) Keypad (16) KS0108 (3) LCD (76) LM35 (3) Master/Slave (2) MAX7221 (1) MCP23017 (8) MCP23S17 (7) MCP4921 (1) MCP4922 (2) Meter (3) MikroC (2) Module PCB (1) Motor (15) MPLABX (73) Nokia 5110 LCD (4) OLED (2) One-Wire (7) Oscillator (8) PCB (12) PCD8544 (3) PCF8574 (10) PIC (108) PIC12F (3) PIC16 (105) PIC16F628A (3) PIC16F630 (2) PIC16F716 (4) PIC16F818 (11) PIC16F818/819 (3) PIC16F84A (16) PIC16F876A (2) PIC16F877A (9) PIC16F88 (2) PIC16F887 (60) PIC18 (19) PIC18F1220 (5) PIC18F2550 (5) PIC18F4550 (12) PICKit2 (1) PICMicro PCB (4) Pin Change Interrupt (1) PWM (12) RTC (12) SBN0064G (1) Sensor (13) SH1106 (3) Shift Register (13) Shift Registers (12) SN74HC595N (2) Software TWI (2) SPI (39) ST7735 (1) STM32 (14) STM32 Black Pill (1) STM32 Blue Pill (12) STM32 HAL (8) STM32CubeIDE (16) STM32F103C8T6 (9) STM32F103R6 (3) STM32F401CCU6 (1) SysTick (4) temperature sensor (13) TFT (1) TG12864A (1) Thermometer (22) Timer/Counter (32) TM1637 (2) twi (10) UART (8) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (96)