0% found this document useful (0 votes)
4 views25 pages

Embedded 6

The document provides an overview of embedded systems programming, focusing on microcontroller units and I/O ports, specifically detailing PORTA and its registers. It includes examples of programming in C for controlling LEDs and reading inputs from switches, as well as methods for interfacing with keypads and 7-segment displays. Additionally, it discusses variable types, delay functions, and the use of multiplexers and decoders in display applications.

Uploaded by

hossammedhat81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views25 pages

Embedded 6

The document provides an overview of embedded systems programming, focusing on microcontroller units and I/O ports, specifically detailing PORTA and its registers. It includes examples of programming in C for controlling LEDs and reading inputs from switches, as well as methods for interfacing with keypads and 7-segment displays. Additionally, it discusses variable types, delay functions, and the use of multiplexers and decoders in display applications.

Uploaded by

hossammedhat81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

EMBEDDED SYSTEMS

Computer Engineering and Control Systems Dept.,


Faculty of Engineering,
Mansoura University

Prof. Dr Labib M. Labib


Lec. 6
programming
• Programming a units of MC
• I/O ports
• Ports are A,B,C,D,E each port has two registers
• One of each register is the TRIS X , where X may be A,B, ..
• PORT A
• 0 – TRISA , 8 bits register, control the pins to be input or
output , input = 1 , output= 0
• The second register is called 0 0 1 1 0 1 0

• The second register is called RA6 RA5 RA4 RA3 RA2 RA1 RA0

• PORTA reg. : store Data entered or output


• All the ports are similar to port A
• Cont. PortA
• As portA has pins that may be digital or analog
to define that use a register name ADCon1 = 6
or 7 means the data are digital in port A 12 v

• RA4 is open collector


10 v
each output is 0
1
o/p 0 0
i/p F
1
O
0 Open collector
0
1
RA4 is is input to timer1
Normal TranAct as NOT Can be connected to 12 v why ?
GATE Can drain current greater than
the others
Basics
• 1- Variable types

int Float 32 bits


Character 8bits

2- Numbers
signed
unsigned Decimal 89 = 89
binary 11110011 = 0b11110011
Short 8 bits -128 :127 Hex AF = 0XAF
Int 16 bits -215: 215 --1 Short 8 bits 0 : 255
Long 32 bits -231 :231-1 Int 16 bits 0 : 216 3- Assignment
Long 32 bits 0 : 232
a-Register
Register_name = value;
Ex X=6;
ADCon1 = 6;
B-Bit in register
Except PORTA, B,….. Register_name.bit_number= 0 or 1
Ex TRISC.4 = 1; as input
Ex PORTA.b5=1
5- Delay
Delay_ms(500); delay = 500 msec
Delay_us(500); delay = 500 microsec
Function
Delay
Using timer Loop 1000 …… calculates the
……. Loop 1000 …… time as function
……..
……. ………
Delay in inst.
…. ……. execution
……….
……….. …nop……10 ..
Finished timer
Each inst. Take time of
200 Nano sec

What is the difference between Delay and


timer?
In delay Nop for a certain period
Using In timer start count until finished , while
Mikro.c (Fed.c , Ansi) processor operates
Porotous to simulation

Programming lang. of microcontroller are basic, Pascal, c


and java , assembly
Programming
• Example : Write a program to flash 8 Leds connected to po
• Porta B with delay 500 msec
• First step is draw the circuit of the PIC with five
circuits(Power, Reset, Oscillator, I/p, O/P )
• Second Declaration of variables
• Third Initialization
Example 1
• Main ()
• {

• While(1)
• { TRISB= 0; /* or =0b00000000 or 0X00;
• PORTB = 255;
• Delay_ms(500);
• PORTB = 0;
• Delay_ms(500);
• }
• }
Example 2
• Write a program to count number of pressed of Switch
connected to RA0 and display the result on 8 leds connected
to portB in binary manner until press a switch connected to
RA1 exit
• From the
• loop


Main()
{unsigned short int count= 0; program
• TRISB= 0;
• TRISA = 0XFF;
• ADCON1=6; T0 RA4
• Loop: If (PORTA.B0==1 ) T1 RC1
• { Debounce
• Count ++;
• PORTB = count;
• Delay_ms (300);
• } Pulses on press
• While((PORTA.b0== 1); 200 msec
• Delay_ms (300);
• If (PORTA.b1== 0)
• Goto loop;
• {Poortb=0; Pulses on press with delay
• Count = 0;
solution
• }} We can add capacitors 10 μf between
• switch and ground if it is possible
Keypads
• Types of keypads
• a)Direct line to line

• It uses many input pins


• Easy programming
•Matrix
•If switch
•Is pressesd
•Then a
•Column is
•Short with
•a column
•The columns are connected as input / output pins while the
rows are connected as output/ input pin
7- segments
The 7 segment display is widely used to
display numeric data. They are limited by
the number of segments (LEDs) they have
and hence are not suitable for displaying
text.

Chara.
Common anode or
common cathode
Size
color
Methods of connecting 7 Segments
• a)Direct method
MC 7 seg

• b)Decoder
MC Decoder 7 seg
• Multiplexer
MC 7 seg 7 seg 7 seg 7 seg 7 seg 7 seg

• Logic to use all the 4 digits of the display


• To use all the 4 displays to display 4 different data at the same time, you should follow this sequence.
• Write data to be displayed to Segment 1 into the data latch.
• Enable First Segment.
• Wait for some time.
• Disable First Segment.
• Write the data for the next segment.
• Enable the Next Segment
• Wait for some time.
• Disable that Segment
• Do it for all the segments
• Decoder-Multiplexer

MC decoder 7 seg

Time 20 msc
• Write a program to display a number entered by a keypad
matrix on a 7 segment display
Example 3

Key
pad
• Main()
• {
• Trisb =ox38;
• TRISC = 0;
• PORTB=1;
• IF(PORTB.B3 == 1)
• PORTC =0X06;
• ELSEIF(PORTB.B4== 1)
• PORTC =0X5B;
• ELSEIF(PORTB.B5== 1)
• PORTC =0X4F;
PORTB=2;
IF(PORTB.B3== 1)
PORTC =0X66;
ELSEIF(PORTB.B4== 1)
PORTC =0X6D;
ELSEIF(PORTB.B5== 1)
PORTC =0X7D;
PORTB=4;
IF(PORTB.B3== 1)
PORTC =0X07;
ELSEIF(PORTB.B4== 1)
PORTC =0X7F;
ELSEIF(PORTB.B5== 1)
PORTC =0X4F;
}
}
• Write a program to display a number entered by a keypad
matrix on a 7 segment display using decoder
• Write a program to display a number from 0 to 99 on two
multiplexed 7 segment display with 500 ms delay
• Main ()
• { unsigned short int I, j, z ;
• For (i=0; i<=9; i++)
• WHILE (1){
• For (j=0; i<=9; i++)
• { FOR ( Z =1 , Z <= 50, Z++)
• {PORTC = J;
• PORTB = 1;
• DELAY_MS(5);
• PORTC = I;
• PORTB=2;
• DELAY_MS(5);
• }
• }
• }

You might also like