Embedded System

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

#use I2C(master, sda=PIN_C4, scl=PIN_C3)

long int value;

int i=0;

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

void write_seg(int x1,int x2)

unsigned char x=0;

x=(arr[x1]|0x80);

i2c_start();

i2c_write(0x70);

i2c_write(arr[x1]|0x80);

i2c_stop();

i2c_start();

i2c_write(0x72);

i2c_write(arr[x2]);

i2c_stop();

void main()

setup_adc_ports( RA0_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

while(1)

{set_adc_channel( 0 );

value = read_adc();

i=((value*50)/255);

write_seg(i/10,i%10);
//printf(" %d.%d \n\r",i/10,i%10);

}
PROGRAM

#include<16f877a.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

volatile int a=0,b=0;

void main()

while(1)

a=input(PIN_D0);

b=input(PIN_D1);

printf("\n\r %d %d ",a,b);

b=a&b;

printf("%d",b);

if(b == 0)

output_high(PIN_D4); // MOT

output_high(PIN_D6); // LED:RED

output_low(PIN_D7); // LED:GREEN

else

output_low(PIN_D4); // MOT

output_low(PIN_D6); // LED:GREEN

output_high(PIN_D7); // LED:RED

if(a==0)

output_low(PIN_D6); // LED:GREEN
}

}
PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

#use I2C(master, sda=PIN_C4, scl=PIN_C3)

float value;

unsigned int i=0;

unsigned char arr[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x67};

void delay(unsigned long int del)

while(del--);

void write_seg(int x1,int x2)

i2c_start();

i2c_write(0x70);

i2c_write(arr[x1]);

i2c_stop();

i2c_start();

i2c_write(0x72);

i2c_write(arr[x2]);

i2c_stop();

void main()

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

while(1)

{
set_adc_channel( 1);

value = read_adc();

value = value;

i=((int)(value));

i=(i*2);

printf(" Temperature in Cel %d \n\r",i);

if(i>=99){i=99;}

write_seg(i/10,i%10);

delay(48000);

}
PROGRAM

#include<16f877a.h>z

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

void main()

while(1)

printf(" Vi Microsystems Pvt Ltd Chennai-95 \n");

}
PROGRAM

#include<16F877A.h>

#use delay(clock=20000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

unsigned char a,b,c;

void main()

set_tris_b(0xff);

output_b(0xff);

while(1)

a=input_b();

printf("\n\r Read Switch Value is %x",a);

}
PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

float value;

unsigned int i=0;

void main()

while(1)

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_adc_channel( 1 );

value = read_adc();

i=(int)(value*0.3);

printf(" %d \n\r",i);

if(i>40)

output_low(PIN_D0);

printf(" Above ");

else if(i<35)

output_high(PIN_D0);

printf(" Below ");

}
PROGRAM

#include<16f877a.h>

#include<stdlib.h>

#include<string.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7,stream=GPS)

int i=0;int a1;char a[];

void delay(unsigned long del)

while(del--);

void lcd_cmd(unsigned char cmd)

output_low(pin_E0);

output_low(pin_E1);

delay(500);

output_D(cmd);

delay(500);

output_high(pin_E2);

delay(500);

output_low(pin_E2);

void lcd_dat(unsigned char dat)

output_high(pin_E0);

output_low(pin_E1);

delay(500);

output_D(dat);

delay(500);
output_high(pin_E2);

delay(500);

output_low(pin_E2);

void lcd_init(void)

lcd_cmd(0X38);

delay(500);

lcd_cmd(0X06);

delay(500);

lcd_cmd(0X0C);

delay(500);

lcd_cmd(0X01);

delay(500);

lcd_cmd(0X80);

delay(500);

void lcd_disp(unsigned char w[],unsigned char add)

unsigned char i=0;

for(i=0;w[i]!='\0';i++)

lcd_cmd(add+i);

lcd_dat(w[i]);

delay(500);

void lcd_con(unsigned int con)

{
lcd_dat(((con%1000)/100)+0x30);

lcd_dat(((con%100)/10)+0x30);

lcd_dat((con%10)+0x30);

void print()

unsigned char arr[]={"DISTANCE IN CMS"};

lcd_disp(arr,0x80);

void get()

do{;}while(getc()!='R');

a1=( (getc()-48)*100)+( (getc()-48)*10)+ (getc()-48);

void main()

lcd_init();

print();

while(1)

while(1)

get();

lcd_cmd(0xC0);

lcd_con(a1);

}
PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

long int value;

int i=0;

void main()

while(1)

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_adc_channel( 1 );

value = read_adc();

i=(int)(value/2);

printf("MOISTURE SENSOR: %3d \n",i);

if(i>80)

output_low(PIN_D0);

else

output_high(PIN_D0);

}
PROGRAM

#include<16f877.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=pin_c6,rcv=pin_c7)

long int value;

int i=0;

void main()

while(1)

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_adc_channel( 1 );

value = read_adc(); PIC16F877A

i=(int)(value/2);

printf("LDR SENSOR: %3d \n",i);

if(i>70)

output_low(PIN_D0);

else

output_high(PIN_D0);

}
PROGRAM

#include<16f877a.h>

#include<stdio.h>

#use delay(clock=20000000)

#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)

#use I2C(master, sda=PIN_C4, scl=PIN_C3)

float value=0;

unsigned int i=0;

unsigned long int hour,second,minute,date,month,year;

void delay(unsigned int del)

while(del--);

void set_rtc_time()

i2c_start();

i2c_write(0xa0);

//i2c_write(0x02);

//i2c_write(0x00);

//i2c_write(0x15);

//i2c_write(0x09);

i2c_stop();

void get_rtc_time()

i2c_start();

i2c_write(0xa0);

i2c_write(0x02);

i2c_stop();

i2c_start();
i2c_write(0xa1);

second = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x03);

i2c_stop();

i2c_start();

i2c_write(0xa1);

minute = i2c_read(0);

i2c_stop();

i2c_start();

i2c_write(0xa0);

i2c_write(0x04);

i2c_stop();

i2c_start();

i2c_write(0xa1);

hour = i2c_read(0);

i2c_stop();

void main()

setup_adc_ports( ALL_ANALOG );

setup_adc(ADC_CLOCK_INTERNAL );

set_rtc_time();

while(1)

get_rtc_time();
set_adc_channel( 1 );

value = read_adc();

i=(int)(value/2);

year = 0;

if(minute==0x00)

year=1;

if(minute==0x02)

year=1;

if(minute==0x04)

year=1;

printf(" %d Time : %x %x %x \n\r",i,hour,minute,second);

if((year==1)|| (i>70))

output_high(PIN_D0);

if((year==0) && (i<70))

output_low(PIN_D0);

You might also like