krunal siddhapathak
Friday, September 18, 2020
Sunday, November 19, 2017
Friday, May 17, 2013
FASTEST FINGER FIRST USING ATMEGA32
HEY GUYS I HAD DEVELOPED CODE FOR FASTEST FINGER FIRST USING ATMEGA 32 AND USED WIN-AVR ENVIRONMENT FOR CODING.PLEASE GO THROUGH IT.
#include <avr/io.h>
#include <util/delay.h>
void ProcessPressedButton(int ButtonPressed);
void ProcessReleasedButton(int ButtonReleased);
int Pressed_Confidence_Level[2];
int Released_Confidence_Level[2];
int Pressed[2];
int LEDNumber[2];
int main(void)
{
DDRB = 0b01111111;
DDRD = 0b01111111;
PORTB = 0b10000000;
PORTD = 0b10000000;
while (1)
{
if (bit_is_clear(PINB, 7))
{
ProcessPressedButton(0);
}
else
{
ProcessReleasedButton(0);
}
if (bit_is_clear(PIND, 7))
{
ProcessPressedButton(1);
}
else
{
ProcessReleasedButton(1);
}
}
}
void ProcessPressedButton(int ButtonPressed)
{
Pressed_Confidence_Level[ButtonPressed] ++;
if (Pressed_Confidence_Level[ButtonPressed] > 500)
{
if (Pressed[ButtonPressed] == 0)
{
Pressed[ButtonPressed] = 1;
if (ButtonPressed == 0) PORTB |= 1 << LEDNumber[ButtonPressed];
if (ButtonPressed == 1) PORTD |= 1 << LEDNumber[ButtonPressed];
LEDNumber[ButtonPressed] ++;
if (LEDNumber[ButtonPressed] >6)
{
for(int i=0;i < 10;i++)
{
if (ButtonPressed == 0) PORTB = 0b11111111;
if (ButtonPressed == 1) PORTD = 0b11111111;
_delay_ms(10);
if (ButtonPressed == 0) PORTB = 0b10000000;
if (ButtonPressed == 1) PORTD = 0b10000000;
_delay_ms(10);
}
LEDNumber[0] = 0;
LEDNumber[1] = 0;
PORTB = 0b10000000;
PORTD = 0b10000000;
}
}
Pressed_Confidence_Level[ButtonPressed] = 0;
}
}
void ProcessReleasedButton(int ButtonReleased)
{
Released_Confidence_Level[ButtonReleased] ++;
if (Released_Confidence_Level[ButtonReleased] > 500)
{
Pressed[ButtonReleased] = 0;
Released_Confidence_Level[ButtonReleased] = 0;
}
}
#include <avr/io.h>
#include <util/delay.h>
void ProcessPressedButton(int ButtonPressed);
void ProcessReleasedButton(int ButtonReleased);
int Pressed_Confidence_Level[2];
int Released_Confidence_Level[2];
int Pressed[2];
int LEDNumber[2];
int main(void)
{
DDRB = 0b01111111;
DDRD = 0b01111111;
PORTB = 0b10000000;
PORTD = 0b10000000;
while (1)
{
if (bit_is_clear(PINB, 7))
{
ProcessPressedButton(0);
}
else
{
ProcessReleasedButton(0);
}
if (bit_is_clear(PIND, 7))
{
ProcessPressedButton(1);
}
else
{
ProcessReleasedButton(1);
}
}
}
void ProcessPressedButton(int ButtonPressed)
{
Pressed_Confidence_Level[ButtonPressed] ++;
if (Pressed_Confidence_Level[ButtonPressed] > 500)
{
if (Pressed[ButtonPressed] == 0)
{
Pressed[ButtonPressed] = 1;
if (ButtonPressed == 0) PORTB |= 1 << LEDNumber[ButtonPressed];
if (ButtonPressed == 1) PORTD |= 1 << LEDNumber[ButtonPressed];
LEDNumber[ButtonPressed] ++;
if (LEDNumber[ButtonPressed] >6)
{
for(int i=0;i < 10;i++)
{
if (ButtonPressed == 0) PORTB = 0b11111111;
if (ButtonPressed == 1) PORTD = 0b11111111;
_delay_ms(10);
if (ButtonPressed == 0) PORTB = 0b10000000;
if (ButtonPressed == 1) PORTD = 0b10000000;
_delay_ms(10);
}
LEDNumber[0] = 0;
LEDNumber[1] = 0;
PORTB = 0b10000000;
PORTD = 0b10000000;
}
}
Pressed_Confidence_Level[ButtonPressed] = 0;
}
}
void ProcessReleasedButton(int ButtonReleased)
{
Released_Confidence_Level[ButtonReleased] ++;
if (Released_Confidence_Level[ButtonReleased] > 500)
{
Pressed[ButtonReleased] = 0;
Released_Confidence_Level[ButtonReleased] = 0;
}
}
Digital lock using arduino uno
HEY GUYS THIS IS THE CODE FOR DIGITAL LOCK USING ARDUINO UNO
PLEASE GO THROUGH IT
/*Circuit connections for LCD Interfacing:
* LCD RS pin to
digital pin 12
* LCD Enable pin to
digital pin 11
* LCD D4 pin to
digital pin 5
* LCD D5 pin to
digital pin 4
* LCD D6 pin to
digital pin 3
* LCD D7 pin to
digital pin 2
* LCD R/W pin to
ground
* 10K resistor:
* ends to +5V and
ground
* wiper to LCD VO pin
(pin 3)
*Circuit connections
for Keypad Interfacing:
*/
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
char* secretCode = "2218";//character pointer
secretCode stores the starting address of the string "2218"
int p=0;
const byte rows = 4;//four rows
const byte cols = 3;//three columns
char keys[rows][cols] =
{
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[rows] = {9,8,7,6};//connect to the row pinouts
of the keypad
byte colPins[cols] = {12,11,10};//connect to the column
pinouts of the keypad
Keypad nirma = Keypad(makeKeymap(keys), rowPins, colPins,
rows, cols);
int redPin = 4;
int greenPin =2;
void setup()
{
pinMode(redPin,
OUTPUT);
pinMode(greenPin,
OUTPUT);
lcd.begin(16,2);//set up the LCD's number of columns and rows
lcd.print("Enter password ");
//setLocked(true);
}
void loop()
{
lcd.setCursor(0, 1);
char input =
nirma.getKey();//returns the key that is pressed
for(int
i=3;i>0;i--)//Loop controls no. of attempts(3)
{
for(int
k=1;k<5;k++)//Loop controls no. of keypad presses(4)
{
if (input == '*'
|| input == '#')
{
p = 0;
setLocked(true);
lcd.println("Invalid
numerals");//Red LED is on untill all 4 no.s have been pressed
}
else if(input ==
secretCode[p])
{
lcd.print("*");
p++;
if(p == 4)
{
setLocked(false);//Green LED glows when all 4 no.s have been entered
lcd.println("Correct Password");
}
}
else
{
lcd.print("*");
p++;
if(p == 4)
{
setLocked(true);
lcd.println("I am locked.");
lcd.println(i-1); lcd.print("trials left");
if(i==1)
{
lcd.println("I am blocked.");
}
}
}
}
delay(100);
}
}
void setLocked(int locked)//user-defined function setlocked
{
if(locked)
{
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, LOW);
}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin, HIGH);
}
}
LED FLASHING WITH ATMEGA32
HEY GUYS I HAD DEVELOPED FLASHING LED PROGRAM USING FLASHING LED PROGRAM BY USING ATMEGA-32.
#include <avr/io.h>
int main(void)
{
DDRC = 0b00001111;
PORTC = 0b00000000;
DDRD = 0b00001111;
PORTD = 0b00000000;
TCCR1B |= 1<<CS10 | 1<<CS11;
int LEDNumber[2];
while(1)
{
if (TCNT1 > 3906)
{
TCNT1 = 0;
PORTC = 1<<LEDNumber[0];
LEDNumber[0] ++;
if (LEDNumber[0] > 3)
{
LEDNumber[0] = 0;
PORTD = 1<<LEDNumber[1];
LEDNumber[1] ++;
if (LEDNumber[1] > 3)
LEDNumber[1] = 0;
}
}
}
}
#include <avr/io.h>
int main(void)
{
DDRC = 0b00001111;
PORTC = 0b00000000;
DDRD = 0b00001111;
PORTD = 0b00000000;
TCCR1B |= 1<<CS10 | 1<<CS11;
int LEDNumber[2];
while(1)
{
if (TCNT1 > 3906)
{
TCNT1 = 0;
PORTC = 1<<LEDNumber[0];
LEDNumber[0] ++;
if (LEDNumber[0] > 3)
{
LEDNumber[0] = 0;
PORTD = 1<<LEDNumber[1];
LEDNumber[1] ++;
if (LEDNumber[1] > 3)
LEDNumber[1] = 0;
}
}
}
}
VHDL CODE FOR BOOTH MULTIPLIER
HEY GUYS THIS IS THE VHDL CODE FOR BOOTH MULTIPLIER GO THROUGH IT.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity Boot is
port(x, y: in std_logic_vector(3 downto 0);
O: out std_logic_vector(7 downto 0));
end Boot;
architecture boot of Boot is
begin
process(x, y)
variable a: std_logic_vector(8 downto 0);
variable s,p : std_logic_vector(3 downto 0);
variable i:integer;
begin
a := "000000000";
s := y;
a(4 downto 1) := x;
for i in 0 to 3 loop
if(a(1) = '1' and a(0) = '0') then
p := (a(8 downto 5));
a(8 downto 5) := (p - s);
elsif(a(1) = '0' and a(0) = '1') then
p := (a(8 downto 5));
a(8 downto 5) := (p + s);
end if;
a(7 downto 0) := a(8 downto 1);
end loop;
O(7 downto 0) <= a(8 downto 1);
end process;
end boot;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
entity Boot is
port(x, y: in std_logic_vector(3 downto 0);
O: out std_logic_vector(7 downto 0));
end Boot;
architecture boot of Boot is
begin
process(x, y)
variable a: std_logic_vector(8 downto 0);
variable s,p : std_logic_vector(3 downto 0);
variable i:integer;
begin
a := "000000000";
s := y;
a(4 downto 1) := x;
for i in 0 to 3 loop
if(a(1) = '1' and a(0) = '0') then
p := (a(8 downto 5));
a(8 downto 5) := (p - s);
elsif(a(1) = '0' and a(0) = '1') then
p := (a(8 downto 5));
a(8 downto 5) := (p + s);
end if;
a(7 downto 0) := a(8 downto 1);
end loop;
O(7 downto 0) <= a(8 downto 1);
end process;
end boot;
VHDL CODE FOR SQUARE OF 3 BIT NUMBER
HEY GUYS I HAD DEVELOPED VHDL CODE TO FIND SQUARE OF 3 BIT NUMBER .GO THROUGH IT !!!
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity squ is
port(
a : in std_logic_vector( 2 downto 0);
b : out std_logic_vector(5 downto 0)
);
end squ;
architecture squ of squ is
begin
process(a)
begin
b(0)<= a(0);
b(1)<= '0';
b(2)<= a(1) and (not(a(0)));
b(3)<= (a(2) xor a(1)) and a(0);
b(4)<= a(2) and ((not(a(1))) or a(0));
b(5)<= a(2) and a(1);
end process;
end architecture;
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity squ is
port(
a : in std_logic_vector( 2 downto 0);
b : out std_logic_vector(5 downto 0)
);
end squ;
architecture squ of squ is
begin
process(a)
begin
b(0)<= a(0);
b(1)<= '0';
b(2)<= a(1) and (not(a(0)));
b(3)<= (a(2) xor a(1)) and a(0);
b(4)<= a(2) and ((not(a(1))) or a(0));
b(5)<= a(2) and a(1);
end process;
end architecture;
Subscribe to:
Posts (Atom)