0% found this document useful (0 votes)
31 views

Digital Output: 1.to Enable Single Bit

The document describes 7 programs for controlling digital output on a PIC microcontroller. The programs demonstrate: 1) enabling a single bit, 2) enabling all bits, 3) blinking a single bit, 4) toggling all bits, 5) binary counting, 6) shifting LEDs bitwise, and 7) shifting LEDs using shift operators. Each program uses loops and bit manipulation to control the output pins for the purpose of testing digital output functionality.

Uploaded by

Om Bala
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Digital Output: 1.to Enable Single Bit

The document describes 7 programs for controlling digital output on a PIC microcontroller. The programs demonstrate: 1) enabling a single bit, 2) enabling all bits, 3) blinking a single bit, 4) toggling all bits, 5) binary counting, 6) shifting LEDs bitwise, and 7) shifting LEDs using shift operators. Each program uses loops and bit manipulation to control the output pins for the purpose of testing digital output functionality.

Uploaded by

Om Bala
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Digital output:

1.To enable single bit


#include<pic.h>
void main()
{
TRISD=0b11111110;//register declaration
PORTD=0b11111111;//clear port
while(1)
{
RD0=0;
}
}

2.To enable all Bits:


#include<pic.h>
unsigned int i;
void main()
{
TRISD=0x00;//register declaration
PORTD=0xFF;//clear port
while(1)
{
PORTD=0x00;
}
}

3.To blink a single Bit

#include<pic.h>
unsigned int i;
void main()
{
TRISD=0b11111110;//register declaration
PORTD=0xFF;//clear port
while(1)
{
RD0=0;
for(i=0;i<40000;i++);
RD0=1;
for(i=0;i<40000;i++);
}
}

4.Toggle all bits


#include<pic.h>
unsigned int i;
void main()
{
TRISD=0x00;
PORTD=0xFF;
while(1)
{
PORTD=0x55;
for(i=0;i<60000;i++);
PORTD=0xAA;

for(i=0;i<40000;i++);
}
}

5.Binary counting
#include<pic.h>
unsigned int i,j;
void main()
{
TRISD=0x00;
PORTD=0xFF;
while(1)
{
for(i=0;i<=256;i++)
{
PORTD=~i;
for(j=0;j<60000;j++);
}
}
}

6.Led shift bitwise


#include<pic.h>
unsigned int i;
void main()
{
TRISD=0x00;
PORTD=0xFF;

while(1)
{
PORTD=0b11111110;
for(i=0;i<40000;i++);
PORTD=0b11111101;
for(i=0;i<40000;i++);
PORTD=0b11111011;
for(i=0;i<40000;i++);
PORTD=0b11110111;
for(i=0;i<40000;i++);
PORTD=0b11101111;
for(i=0;i<40000;i++);
PORTD=0b11011111;
for(i=0;i<40000;i++);
PORTD=0b10111111;
for(i=0;i<40000;i++);
PORTD=0b01111111;
for(i=0;i<40000;i++);
}
}

7.Led shift by shift operator


#include<pic.h>
unsigned int i,j,a;
void main()
{
TRISD=0x00;

PORTD=0xFF;
j=0;
a=0x01;
while(j<9)
{
PORTD=~a;
a=a<<1;
for(i=0;i<60000;i++);
j++;
}
}

You might also like