/*
* code_pcbGEN01.c
*
* Created: 15/02/2020 1:08:59 AM
* Author: Mahesh Nigam
*/
#define F_CPU 12000000UL //Setting F_CPU to the frequency of the microcontroller
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <avr/wdt.h>
#include <stdlib.h>
#include <string.h>
#include "drivers/16x2lcd/hd44780.h"
//FUNCTION DECLARATIONS
void button_tone_delay();
unsigned char READ_EEPROM(unsigned int uiAddress);
//dedicated variables
char str[20];
//START-project specific variables
char seven_segment_code[11]={0b11100111,0b00100001,0b11001011,0b01101011,0b00101101,0b01101110,0b11101110,0b00100011,0b11101111,0b01101111,0b00010000};
unsigned int buffer_num=0;
unsigned char digit_num1=0;
unsigned char digit_num2=0;
unsigned char digit_num3=0;
unsigned int life_value=0;
char start_test=0;
#define segment_port PORTD //declare this port as output anywhere
//END-project specific variables
//timer variables
unsigned int s=0;
unsigned int s_last=0;
unsigned int s_last_display=0;
unsigned char s_increment_status=0;
unsigned int ms1=0;
unsigned int common_ms1_timer=0;
char sms_sent=0;
//temp_variable
char temp_str[20]="000";
unsigned char char_temp=0;
unsigned int int_temp=0;
//eeprom address assignment
//#define xxxxxxx 0x4001
//output defines start
#define output_port2 PORTB
#define output_ddr2 DDRB
#define sel_digit1 0
#define sel_digit2 1
#define sel_digit3 2
#define buzzer 3
//output defines start
#define output_port4 PORTD
#define output_ddr4 DDRD
void init_outputs()
{
output_ddr2 |= ((1<<sel_digit1) | (1<<sel_digit2) | (1<<sel_digit3) | (1<<buzzer));
output_port2 &= ~((1<<sel_digit1) | (1<<sel_digit2) | (1<<sel_digit3) | (1<<buzzer)); //initial value as '0's
output_ddr4 = 0xff; //all as output
output_port4 = 0x0; //initial value as '0's
}
//output defines end
//START- system time generator
void init_timer0(){ //initialize timer0
TIMSK |= (1<<TOIE0); //ENABLE TIMER0
TCCR0 = (0x03); //PRESCALER=1:64
TCNT0 = 70; // 1ms timer value
sei(); // Interrupt Enabled GLOBALLY
}
ISR(TIMER0_OVF_vect) {
unsigned char sreg = SREG;
cli(); // Disable Global interrupt
TCNT0 = 70; // 1ms timer value
//main system time controlling
ms1++;
common_ms1_timer++;
//START-updating seven segment
if((buffer_num>999) || (buffer_num<0)){buffer_num=0;}
if(ms1%3==0){
output_port2 &=~((1<<sel_digit1) | (1<<sel_digit2) | (1<<sel_digit3));
output_port2 |= ((1<<sel_digit1));
digit_num1=(buffer_num%100)%10;
segment_port = ~seven_segment_code[digit_num1];
}
if(ms1%3==1){
output_port2 &=~((1<<sel_digit1) | (1<<sel_digit2) | (1<<sel_digit3));
output_port2 |= ((1<<sel_digit2));
digit_num2=(buffer_num%100)/10;
segment_port = ~seven_segment_code[digit_num2];
}
if(ms1%3==2){
output_port2 &=~((1<<sel_digit1) | (1<<sel_digit2) | (1<<sel_digit3));
output_port2 |= ((1<<sel_digit3));
digit_num3=(buffer_num/100);
segment_port = ~seven_segment_code[digit_num3];
}
//END-updating seven segment
if(ms1>1000){ms1=0;
if(s_increment_status==0){
s_increment_status=1;
s++;
//timeout
}
}
else{s_increment_status=0;}
SREG = sreg;
}
//END- system time generator
int main(void){
//init_sensor();
init_outputs();
init_timer0();
buffer_num=0;
while(1){
buffer_num++;
_delay_ms(1000);
}
}
NOTE: If your have any doubt in coding or not able to understant how to use it in your code, feel free to ask me in below comment section.
Seven Segment Code table with connecting pins
PIN | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
SEGMENT ALPHABET | e | d | c | dp | g | f | a | b |
0 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 |
1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 |
2 | 1 | 1 | 0 | 0 | 1 | 0 | 1 | 1 |
3 | 0 | 1 | 1 | 0 | 1 | 0 | 1 | 1 |
4 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 1 |
5 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
6 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
7 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 1 |
8 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
9 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
dot point DP | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 1 |
This table can be used for both, common cathode (CC) as well as common anode (CA) seven segment display.
NOTE: If your have any doubt in coding or not able to understant how to use it in your code, feel free to ask me in below comment section.
Posted By :
Mahesh Nigam
(Scientist)
2020-02-15 16:49
See Author's other Published Topics
Peoples
Peoples
Comments...
shivam tayal: what is program language?
Mahesh Nigam(Scientist): Above program was written in C language
Write Your Comment