Documente Academic
Documente Profesional
Documente Cultură
R
Educational and Research Institute
University
XILINX VHDL
01(A) HALF ADDER
01(B) FULL ADDER
02(A) HALF SUBTRACTOR
03(B) FULL SUBTRACTOR
04 MULTIPLEXER
05 DE - MULTIPLEXER
06 ENCODER
07 DECODER
PIC Microcontroller
01 Study Of PIC Microcontroller
02 Design of LED Display
03 Design DC Motor Controller
04 Design of LCD Display
05 Design of RS 232
Verilog HDL
EX. NO: 01 A Date:
HALF ADDER
AIM:
PROGRAM:
module Halfadd1(i0, i1, sum, c_out);
input i0;
input i1;
output sum;
output c_out;
xor(sum,i1,i2);
and(c_out,i1,i2);
endmodule
OUTPUT:
TRUTH TABLE:
RESULT:
AIM:
PROGRAM:
OUTPUT:
TRUTH TABLE:
i1 i2 C_in C_out Sum
0 0 0 0 0
0 0 1 0 1
0 1 0 0 1
0 1 1 1 0
1 0 0 0 1
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1
SIMULATION OUTPUT:
RESULT:
PROGRAM:
input i0;
input i1;
output bor;
output dif;
wire i0n;
not(i0n,i0);
xor(dif,i0,i1);
and(bor,i0n,i1);
endmodule
OUTPUT:
TRUTH TABLE:
SIMULATION OUTPUT:
RESULT:
PROGRAM:
input b_in;
input i0;
input i1;
output dif;
output b_out;
assign {b_out,dif}=i0-i1-b_in;
end module;
OUTPUT:
TRUTH TABLE:
SIMULATION OUTPUT:
RESULT:
PROGRAM:
input i0;
input i1;
input i2;
input i3;
input s0;
input s1;
output out;
wire s1n,s0n;
wire y0,y1,y2,y3;
not (s1n,s1);
not (s0n,s0);
and (y0,i0,s1n,s0n);
and (y1,i1,s1n,s0);
and (y2,i2,s1,s0n);
and (y3,i3,s1,s0);
or (out,y0,y1,y2,y3);
end module;
OUTPUT:
TRUTH TABLE:
S0 S1 OUTPUT
0 0 1
0 1 1
1 0 0
1 1 1
SIMULATION OUTPUT:
RESULT:
AIM:
PROGRAM:
input in;
input s0;
input s1;
output out0;
output out1;
output out2;
output out3;
wire s0n,s1n;
not(s0n,s0);
not(s1n,s1);
and (out0,in,s1n,s0n);
and (out1,in,s1n,s0);
and (out2,in,s1,s0n);
and (out3,in,s1,s0);
endmodule;
OUTPUT:
TRUTH TABLE:
SIMULATION OUTPUT:
RESULT:
D-FLIP FLOP
AIM:
PROGRAM:
input clock;
input reset;
input d;
output q;
reg q;
if(~reset)q=0;
else q=d;
endmodule
OUTPUT:
TRUTH TABLE:
RESULT:
T-FLIP FLOP
AIM:
PROGRAM:
input Clock;
input Reset;
input t;
output q;
reg q;
if(~Reset) q=0;
else q=q;
endmodule
OUTPUT:
TRUTH TABLE:
CLOCK RESET Q(~Q) INPUT (T) OUTPUT
0 0 0 0(1)
1 0 0 0(1)
0 0 1 0(1)
1 0 1 0(1)
0 0 0 0(1)
1 0 0 0(1)
0 1 1 0(1)
1 1 1 1(0)
0 1 0 1(0)
1 1 0 1(0)
0 1 1 1(0)
1 1 1 0(1)
0 0 0 0(1)
1 0 0 0(1)
0 0 0 0(1)
SIMULATION OUTPUT:
RESULT:
PROGRAM:
input Clock ;
input Reset;
input j;
input k;
output q;
reg q;
if(~Reset)q=0;
else
begin
case({j,k})
2'b00: q=q;
2'b01: q=0;
2'b10: q=1;
2'b11: q=~q;
endcase
end
endmodule
OUTPUT:
TRUTH TABLE:
RESULT:
ENCODER
AIM:
PROGRAM:
input i0;
input i1;
input i2;
input i3;
output out0;
output out1;
reg out0,out1;
always @(i0,i1,i2,i3)
case({i0,i1,i2,i3})
4'b1000:{out0,out1}=2'b00;
4'b0100:{out0,out1}=2'b01;
4'b0010:{out0,out1}=2'b10;
4'b0001:{out0,out1}=2'b11;
endcase
endmodule
OUTPUT:
TRUTH TABLE:
I0 I1 I2 I3 Out0 Out1
1 0 0 0 0 0
0 1 0 0 0 1
0 0 1 0 1 0
0 0 0 1 1 1
SIMULATION OUTPUT:
RESULT:
DECODER
AIM:
PROGRAM:
input i0;
input i1;
output out0;
output out1;
output out2;
output out3;
reg out0,out1,out2,out3;
always @(i0,i1)
case({i0,i1})
2'b00:{out0,out1,out2,out3}=4'b1000;
2'b01:{out0,out1,out2,out3}=4'b0100;
2'b10:{out0,out1,out2,out3}=4'b0010;
2'b11:{out0,out1,out2,out3}=4'b0001;
endcase
endmodule
OUTPUT:
TRUTH TABLE:
RESULT:
HALF ADDER
STRUCTURAL MODEL
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity haladdbe is
Port ( a : in std_logic;
b : in std_logic;
s : out std_logic;
c : out std_logic);
end haladdbe;
begin
s<=(a xor b);
c<=(a and b);
end Behavioral;
OUTPUT
RESULT:
FULL ADDER
STRUCTURAL MODEL
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity full3 is
Port ( a : in std_logic;
b : in std_logic;
c : in std_logic;
s: out std_logic;
Carry:out std_logic);
end full3;
begin
s<=(a xor b) xor c;
carry<=(a and b) or (a and c) or (b and c);
end Behavioral;
OUTPUT
RESULT:
HALF SUBTRACTOR
STRUCTURAL MODEL
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity hlfsub is
Port ( a : in std_logic;
b : in std_logic;
y : out std_logic;
x : out std_logic);
end hlfsub;
begin
y<= a xor b;
x<= b and ( not(a));
end Behavioral;
OUTPUT
RESULT:
FULL SUBTRACTOR
STRUCTURAL MODEL
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fulsubbe is
Port ( x : in std_logic;
y : in std_logic;
z : in std_logic;
d : out std_logic;
b : out std_logic);
end fulsubbe;
begin
d<=x xor y xor z;
b<=(not(x) and y) or (y and z) or (z and (not(x)));
end Behavioral;
OUTPUT
RESULT:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux is
Port ( a : in std_logic;
b : in std_logic;
c : in std_logic;
d : in std_logic;
s0 : in std_logic;
s1 : in std_logic;
q : out std_logic);
end mux;
begin
process(s0,s1,a,b,c,d)
begin
if s0= '0' then
if s1= '0' then
q<=a;
else
q<=b;
end if;
end if;
if s0='1' then
if s1='0' then
q<=c;
else
q<=d;
end if;
end if;
end process;
end Behavioral;
OUTPUT:
RESULT:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity demux is
Port ( a : in std_logic;
b : in std_logic;
y0 : out std_logic;
y1 : out std_logic;
y2 : out std_logic;
y3 : out std_logic);
end demux;
begin
process(a,b)
begin
if a='0' then
if b='0' then
y0<='0';
y1<='1';
y2<='1';
y3<='1';
else
y0<='1';
y1<='0';
y2<='1';
y3<='1';
end if;
end if;
if a='1' then
if b='0' then
y0<='1';
y1<='1';
y2<='0';
y3<='1';
else
y0<='1';
y1<='1';
y2<='1';
y3<='1';
end if;
end if;
end process;
end Behavioral;
OUTPUT
RESULT:
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity encoder is
Port ( a : in std_logic;
b : in std_logic;
c : in std_logic;
d : in std_logic;
x : out std_logic;
y : out std_logic);
end encoder;
begin
process(a,b,c,d)
begin
if a='0' then
if b='0' then
if c='0' then
if d='0' then
x<='0';
y<='0';
elsif d='1' then
x<='0';
y<='1';
elsif c='1' then
x<='1';
y<='0';
elsif b='1' then
x<='1';
y<='1';
end if;
end if;
end if;
end if;
end process;
end Behavioral;
OUTPUT
RESULT:
DECODER
AIM:
PROGRAM:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decoder is
Port ( a : in std_logic;
b : in std_logic;
d1 : out std_logic;
d2 : out std_logic;
d3 : out std_logic;
d4 : out std_logic);
end decoder;
begin
process(a,b)
begin
if a='0' then
if b='0' then
d1<='1';
d2<='0';
d3<='0';
d4<='0';
else
d1<='0';
d2<='1';
d3<='0';
d4<='0';
end if;
end if;
if a='1' then
if b='0' then
d1<='0';
d2<='0';
d3<='1';
d4<='0';
else
d1<='0';
d2<='0';
d3<='0';
d4<='1';
end if;
end if;
end process;
end Behavioral;
OUTPUT
RESULT:
PIC Microcontroller
Introduction:
The PIC16F877A CMOS FLASH-based 8-bit microcontroller is upward compatible with the PIC16C5x, PIC12Cxxx and
PIC16C7x devices. It features 200 ns instruction execution, 256 bytes of EEPROM data memory, self programming, an
ICD, 2 Comparators, 8 channels of 10-bit Analog-to-Digital (A/D) converter, 2 capture/compare/PWM functions, a
synchronous serial port that can be configured as either 3-wire SPI or 2-wire I2C bus, a USART, and a Parallel Slave Port.
Lead-free; RoHS-compliant
Operating speed: 20 MHz, 200 ns instruction cycle
Operating voltage: 4.0-5.5V
Industrial temperature range (-40° to +85°C)
15 Interrupt Sources
35 single-word instructions
All single-cycle instructions except for program branches (two-cycle)
Analog Features
10-bit, 8-channel A/D Converter
Brown-Out Reset
Analog Comparator module
o 2 analog comparators
o Programmable on-chip voltage reference module
o Programmable input multiplexing from device inputs and internal VREF
o Comparator outputs are externally accessible
Result:
LED Display
AIM:
To Write a Program to test the working of LED using CCS C compiler and Proteus Simulator.
PROGRAM:
#include <16F877a.h>
#include <string.h>
#bit LED1=0x7.0
#bit LED2=0x7.1
Void main ()
set_tris_c(0x00);
LED1=LED2=1;
While (22)
LED2=LED1=0;
OUTPUT:
RESULT:
Thus the Program for working of LED is compiled and simulated using CCS C compiler and Proteus Simulator.
PROGRAM:
#include<16F877A.h>
#include<string.h>
#fuses NOWDT,PUT,HS,NOPROTECT
#use delay(clock=20000000)
void main()
set_tris_a(0x00);
while(1)
output_low(m1f);
output_high(m1r);
delay_ms(1000);
output_high(m1f);
output_low(m1r);
delay_ms(1000);
}}
OUTPUT:
RESULT:
Thus the Program for rotation of DC 12V Motor in forward and reverse direction is compiled and simulated
using CCS C compiler and Proteus Simulator.
PROGRAM:
#include<16f877a.h>
#include<stdlib.h>
#include <string.h>
#include<ctype.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,PUT,NOLVP
#define RS PIN_B7
#define E PIN_B6
void disp_init(void);
unsigned char i;
output_c(dat);
for(i=0;i<255;i++);
output_low(RS);
for(i=0;i<255;i++);
output_high(E);
for(i=0;i<255;i++);
output_low(E);
unsigned char i;
output_c(x);
for(i=0;i<255;i++);
output_high(RS);
for(i=0;i<255;i++);
output_high(E);
for(i=0;i<255;i++);
output_low(E);
void disp_init(void)
{
command(dispfunc);
command(dispccurr);
command(blkoff);
command(dispclear);
command(selrow2);
command(dispclear);
void main()
char temp;
char temp4;
set_tris_c(0x00);
set_tris_e(0x00);
set_tris_b(0xf1);
output_low(RS);
output_low(E);
disp_init();
command(0X01);
command(0X80);
delay_ms(500);
}
OUTPUT:
RESULT:
Thus the Program for LCD Display is compiled and Simulated using CCS C compiler and Proteus
Simulator.
PROGRAM:
#include<16f877a.h>
#include<stdlib.h>
#include <string.h>
#include<ctype.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,PUT,NOLVP
void get();
{
unsigned char temp0;
set_adc_channel(0);
delay_ms(10);
temp0 = read_adc();
delay_ms(10);
return temp0;
}
void main()
{
setup_adc_ports(A_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
while(1)
{
t1=adc0();
fputc('A',com_1);
delay_ms(5000);
}
}
OUTPUT:
RESULT:
Thus the Program for sending data from PIC to PC through RS232 is compiled and Simulated using
CCS C compiler and Proteus Simulator.