From App
From App
#include<pic.h>
#include<ADC.h>
#include<stdlib.h>
#include<lcd.h>
#include<uart.h>
#define _XTAL_FREQ 16000000
__CONFIG(0X3F7A);
void main()
{
char c[5],c1[5];
int temp,n;
T0SE=1;
uart_init(9600);
lcd_init();
lcd_clear();
adc_init();
while(1)
{
lcd_goto(1,1);
lcd_puts("Temp= ");
lcd_goto(2,1);
lcd_puts("Speed= ");
lcd_goto(2,8);
itoa(c1,n,10);
lcd_puts(c1);
lcd_goto(2,12);
lcd_puts("RPM");
temp=(adc_read(0)/2)-1;
lcd_goto(1,7);
itoa(c,temp,10);
lcd_puts(c);
uart_write('#');
uart_puts(c);
uart_write('$');
uart_puts(c1);
TMR0=0X00;
__delay_ms(2000);
n=TMR0;
n=n*30;
lcd_clear(); } }
APPENDIX B
GPIO.setup(31,1,pull_up_down=GPIO.PUD_UP) #Horn
GPIO.setup(33,1,pull_up_down=GPIO.PUD_UP) #Brake
GPIO.setup(35,1,pull_up_down=GPIO.PUD_UP)#right indicator
GPIO.setup(37,1,pull_up_down=GPIO.PUD_UP)#left indicator
GPIO.setup(32,1,pull_up_down=GPIO.PUD_UP)#piezo sensor
msg = MIMEMultipart()
msg['From'] = fromaddr
msg['To'] = toaddr
msg['Subject'] = sub
msg.attach(MIMEText(body, 'plain'))
filename = "Image"
attachment = open("/home/pi/Desktop/image.jpg", "rb")
msg.attach(part)
time.sleep(delay)
#--------------------------------- B.7 -------------------------------------------------------------------------#
data=str(data)
l=len(data)
rpm=data[data.index('$')+1:l]
print 'rpm='+rpm
print 'temp='+temp
except:
print 'Waiting'
time.sleep(delay)
#--------------------------------- B.10 -------------------------------------------------------------------------#
if(GPIO.input(37)==0):
GPIO.output(10,1)
print 'Left Indicator ON'
LI='\nLeft Indicator ON'
LIS='LION,'
else:
GPIO.output(10,0)
LI=''
LIS='LIOFF,'
if(GPIO.input(38)==0):
print 'Alcohol Detected'
al='\nAlcohol Detected'
als='AD'
else:
als='AnD'
al=''
if(GPIO.input(31)==0):
print 'Horn Pressed'
h='\nHorn Pressed'
HS='HP,'
GPIO.output(40,1)
else:
GPIO.output(40,0)
h=''
HS='HnP,'
if(GPIO.input(33)==0):
print 'Brake Pressed'
b='\nBrake Pressed'
BS='BP,'
else:
b=''
BS='BnP,'
#--------------------------------- B.14 -------------------------------------------------------------------------#
file=open("/home/pi/Desktop/bb.txt","w")
file.write(m)
file.close()
TS=tim[0:3]+tim[4:7]+tim[11:19]+',2017,' #collected date and time
ST=RIS+LIS+HS+BS+als+',Temp='+temp+',RPM='+rpm #data collected as status of
vehicle
#--------------------------------- B.15 -------------------------------------------------------------------------#
while(1):
yy=TS+ST
txn(5622692,yy)
time.sleep(delay)
except:
print "Error: unable to start thread"
while 1:
pass
#--------------------------------- B.12 -------------------------------------------------------------------------#
APPENDIX C
INTCON REGISTER
OPTION_REG REGISTER
D.2 REGISTERS/BITS ASSOCIATED WITH A/D
The conversion of an analog input signal results in a corresponding 10-bit digital number.
The A/D module has high and low-voltage reference input that is software selectable to some
combination of VDD, VSS, RA2 or RA3. It has a unique feature of being able to operate while
the device is in Sleep mode. To operate in Sleep, the A/D clock must be derived from the A/Ds
internal RC oscillator. The A/D module has four registers. These registers are:
The ADRESH:ADRESL register pair is the location where the 10-bit A/D result is loaded
at the completion of the A/D conversion. This register pair is 16 bits wide. The A/D module gives
the flexibility to left or right justify the 10-bit result in the 16-bit result register. The A/D Format
Select bit (ADFM) controls this justification. Figure below shows the operation of the A/D result
justification. The extra bits are loaded with 0s. When an A/D result will not overwrite these
locations (A/D disable), these registers may be used as two general purpose 8-bit registers. The
A/D module can operate during Sleep mode. This requires that the A/D clock source be set to RC
(ADCS1:ADCS0 = 11). When the RC clock source is selected, the A/D module waits one
instruction cycle before starting the conversion. This allows the SLEEP instruction to be
executed which eliminates all digital switching noise from the conversion. When the conversion
is completed, the GO/DONE bit will be cleared and the result loaded into the ADRES register. If
the A/D interrupt is enabled, the device will wake-up from Sleep. If the A/D interrupt is not
enabled, the A/D module will then be turned off, although the ADON bit will remain set.
ADCON0 REGISTER (ADDRESS 1Fh)
The ADCON0 register controls the operation of the A/D module. The ADCON1 register
configures the functions of the port pins. The port pins can be configured as analog inputs (RA3
The PIE1 register contains the individual enable bits for the peripheral interrupts and can
be programmed on bit level
The PIR1 register contains the individual flag bits for the peripheral interrupts.
RCSTA: RECEIVE STATUS AND CONTROL REGISTER (ADDRESS 18h)
TXSTA: TRANSMIT STATUS AND CONTROL REGISTER (ADDRESS 98h)