Learning PIC Coding using C Language

Here, I'm sharing PIC C Language for coding various type of hardware. I'm using MPLab Software with Hi-Tech Compiler.

Firstly, I start with LED. You can connect LED to PIC by 2 ways.
[​IMG]
Let say you connect Active High LED on Port B0. Signal High will turn 'ON' LED and signal Low will turn 'OFF' LED.
You can program like
RB0=1;      //Turn ON LED
RB0=0;      //Turn OFF LED
or
PORTB=0b00000001;      //Turn ON LED
PORTB=0b00000000;      //Turn OFF LED
To do LED Blinking
for( ; ; ){  //loop forever
           PORTB=0b00000001;      //Turn ON LED
           for(i=0;i<=100;i++) __delay_ms(10);
           PORTB=0b00000000;      //Turn OFF LED
           for(i=0;i<=100;i++) __delay_ms(10);}

Replies

  • shahrul
    shahrul
    How to connect seven segment display?
    Actually, seven segment display not much differ with LED. The seven segment display is only like 8 LED's. 2 way of connection.
    [​IMG]

    You do 'ON' and 'OFF' depending the position of the LED. Convert into this function.
    char convert(char dec)
    {char segment;
    switch(dec){
    case 0:segment=0b11111100;break;
    case 1:segment=0b01100000;break;
    case 2:segment=0b11011010;break;
    case 3:segment=0b11110010;break;
    case 4:segment=0b01100110;break;
    case 5:segment=0b10110110;break;
    case 6:segment=0b10111110;break;
    case 7:segment=0b11100000;break;
    case 8:segment=0b11111110;break;
    case 9:segment=0b11110110;break;}
    return segment;
    }
  • Codes Guides
    Codes Guides
    Good posts. In my experience, PICs do better sinking current than sourcing. I would recommend connecting the LEDs so that the PIC sinks the currents.

    - CG
    #-Link-Snipped-#
  • shahrul
    shahrul
    Codes Guides
    Good posts. In my experience, PICs do better sinking current than sourcing. I would recommend connecting the LEDs so that the PIC sinks the currents.
    Yes, that's good. Thank you for sharing experience. I know but I did't follow, I still do sourcing current.
  • Codes Guides
    Codes Guides
    Newer PICs may be better. Old ones used to drop a lot of voltage when sourcing current.
  • shahrul
    shahrul
    How to read push button?
    You can connect push button in two ways.
    [​IMG]
    At example, I have 4 push button, then I convert the input into value. Any push button need to press and released.
    int read_button()
    {int i;
    if(PB1==0){
        while(PB1==0) continue;    //wait until PB1 release
        i=1;}
    else if(PB2==0){
        while(PB2==0) continue;    //wait until PB2 release
        i=2;}
    else if(PB3==0){
        while(PB3==0) continue;    //wait until PB3 release
        i=3;}
    else if(PB4==0){
        while(PB4==0) continue;    //wait until PB4 release
        i=4;}
    else i=0;
    return i;
    }

You are reading an archived discussion.

Related Posts

Please tell me some free web hosting sites that can provide me PHP support with Mysql?
The link is https://result.annauniv.edu/result/result10.html
i have installed vista in my laptop and have 20 gb of unallocated memory whenever i tries to make a new partition it denies. and also cannot extend any partition?
any body can tell me when i compressed my c drive it said boot manager got compressed and window got crashed? 😕
As I have already discussed in one of my thread that Banks are not the charitiable organizations, they are money making organizations. Money creation is the process by which new...