Embedded 6
Embedded 6
• The second register is called RA6 RA5 RA4 RA3 RA2 RA1 RA0
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
• 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
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
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);
• }
• }
• }