Tuesday, May 27, 2014

4 Channel IR remote control

Hello,
This time I have finished writing the codes for the transmitter and receiver part of a 4 channel IR remote control based on PIC16F84A. The schematic of the tow parts are shown below. Here the crystal is 12Mhz.





DC motor speed and direction control using PIC16F877A microcontroller

This schematic shows how to control DC motor speed and also direction at the same time. I have used a 6V DC motor, PIC16F877A with crystal 12Mhz, and some transistors and mosfets to construct the H-bridge which makes us rotate the motor at the 2 directions.



I hope this was useful.

Monday, May 12, 2014

4 Digits 7-Seg Display Counter Using Shift Register

Now let's see how to add switch ti increment our number one by one:
The schematic is as shown below:


The source code in microC is as shown below. You can modify as you want as adding another switch to decrement the number, because we still have 6 available I/O ports and this is the concept of adding the shift register .
The crystal used here was 12MHZ, common cathode 7-seg and 74hct164 shift register.


unsigned short j=0,k=0,l=0,d=0,m=0,n=0,o=0,p=0;
unsigned short seg(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
}
}

void main() {

TRISA=0;
PORTA=0;
TRISB=0XFC;
PORTB=0;
  for(;;){
  if(o==0){ if(PORTB.F2==0){
  j++;
  o=1;}}
  if(PORTB.F2==1){o=0;}
  if(d==0){
  PORTA=0X1E;
  p=seg(j);
            for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
                  d=1;
                  delay_ms(4);}
  if(d==1){
  if(j>9) {j=0;k++;}
  PORTA=0X1D;
  p=seg(k);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d=2;
               delay_ms(4);            }
  if(d==2){
  if(k>9) {k=0;l++;}
  PORTA=0X1B;
  p=seg(l);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d=3;
               delay_ms(4);            }
 if(d==3){
  if(l>9) {l=0;n++;}
  PORTA=0X17;
  p=seg(n);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d=0;
               delay_ms(4);            }
  if(n>9)n=0;
                                     }

}

Sunday, May 11, 2014

4 Digits 7-Seg Display Using Shift Register

We can improve the previous circuit by adding a shift register where we can reduce the number of used I/O pins to 6 instead of 11 I/O pins as shown in this picture.


Also we can add another shift register to the multiplexing circuit and reduce the pins used to 2.
The crystal used is 12mhz and the 7-seg is common cathode type and the shift register is 74HCT164.
The MicroC source code is below:
int i=0,j=0,k=0,l=0,d0=0,m=0,n=0,p=0;
unsigned short seg(unsigned short num) {
switch (num) {
case 0 : return 0x3F;
case 1 : return 0x06;
case 2 : return 0x5B;
case 3 : return 0x4F;
case 4 : return 0x66;
case 5 : return 0x6D;
case 6 : return 0x7D;
case 7 : return 0x07;
case 8 : return 0x7F;
case 9 : return 0x6F;
}
}
void interrupt(){

    i++;
    TMR0 = 0;
    INTCON = 0x20;
}
void main() {
            OPTION_REG = 0x84;
            TMR0 = 0;
            INTCON = 0xA0;
TRISA=0;
PORTA=0;
TRISB=0XFC;
PORTB=0;
  for(;;){
  if(i>300){
  i=0;
  j++;}
  if(d0==0){
  PORTA=0X1E;
  p=seg(j);
            for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
                  d0=1;
                  delay_ms(4);}
  if(d0==1){
  if(j>9) {j=0;k++;}
  PORTA=0X1D;
  p=seg(k);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=2;
               delay_ms(4);            }
  if(d0==2){
  if(k>9) {k=0;l++;}
  PORTA=0X1B;
  p=seg(l);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=3;
               delay_ms(4);            }
 if(d0==3){
  if(l>9) {l=0;n++;}
  PORTA=0X17;
  p=seg(n);
  for(m=0;m<7;m++){
             PORTB.F1=p;
             PORTB.F0=0;
             PORTB.F0=1;
             p=p>>1;}
              d0=0;
               delay_ms(4);            }
  if(n>9)n=0;
                                     }

}

Saturday, May 10, 2014

PIC MCU Open-Drain Output Solution

Many people specially the beginners always have some problems with the RA4 in PORTA for some PIC microcontroller as 16F84A  when they make it as an output. This pin is an open drain. To avoid this problem just add a pull up resistor of about 10K or less as shown.


But I advice for the beginners to set this port as an input.
Good-luck.

4 Digits 7-Segment Display Using Multiplexing Technique






This is a simple Timer counts from 0 to 9999 then it starts again from 0.







The crystal used here is 12MHZ and the 7 segment is common cathode type .
It uses the multiplexing technique which means that it powers just one digit at a time in a very high speed, so we cannot notice it at all.
The hex file is HERE

PORTB LED Flasher

This is a simple project which makes PORTB goes high and low with a delay of 1 second.
تعمل هذه الدارة الالكترونية على جعل portb يعمل كمخارج بحيث تجعل الليدات تومض بفرق قدره ثانية واحدة,


The circuit is shown above. The .HEX file can be downloaded HERE.