Session 5
Session 5
Session 5
presents
µ-CON
Session 5
You need to note down the value of data line only when you
see the "clock line" high.
Baud rate=9600 bits per second 1/9600 =104 µsec
•This is Universal Synchronous Receiver and Transmitter ( USART )
•In UART, a start bit and stop bits are used to synchronize the
incoming data line
•As there is no "clock" line so for synchronization accurate timing is
required so transmissions are carried out with certain standard speeds.
•To transmit a single byte we need to extra bits they are START BIT
AND STOP BIT.
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1SEL = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
P1SEL2 = BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 104; // 1MHz 9600
UCA0BR1 = 0; // 1MHz 9600
UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer empty?
UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
}
#include<msp430g2553.h>
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{ P1OUT ^=BIT0;
P1IFG &= ~BIT3;
while (!(IFG2&UCA0TXIFG));
UCA0TXBUF=string[i++]; //TX->string characters
IFG2 &= ~UCA0TXIFG;
}
This is how a simple program looks like in C.
• c = 2.1 + 3.4
print c (Or just any other arithmetic operation)
•c = “Spider”
print c
print c[0:6]
print c[1:5]
print c[0:6:2]
print c[::-1]
•Extensive support for libraries which make
Python very versatile. You can make websites,
apps or just about anything.
•A strongly typed and easy to understand
interface. For example, variable data types don’t
have to be explicitly specified
•Good community support from users all over the
world. There’ll always be people to help you
debug your code.
Python has while and for loops too.
Although they look a bit different.
•serial : Enables serial data transfer via Python. You
can send and read data using UART.
•win32api and win32con : Allow you to
detect/simulate windows events like key presses,
mouse movement and button presses etc.
•winsound : Allows you to play some sounds from
Python.
•time : Allows for delays to be coded into Python.
This library has some functions to open a serial
port and read data from the device connected to
that port.
serial.Serial(‘PORT’,’BAUD’,timeout = x). This
function opens a serial port specified by ‘PORT’
and sets the baud rate to the ‘BAUD’ value. The
timeout value sets the read timeout.
write(value). This function sends a character to
an opened port.
Read(). This function reads one byte from an
open port. The user can specify the number of
bytes to be read. The default value is one.
Range : 2cm – 400cm
Operates in the 40 Khz ultrasonic
range
Operating voltage : 4.8v – 5.5v
Measuring angle : 15 degrees
It works in a similar fashion to an echo. Initially,
you have to trigger the module (With a 20uS pulse).
After this it sends ultrasonic pulses and records
the time they take to come back. Finally, it sends a
pulse back to the MCU whose width gives an idea
of how far the object is. The distance of the object
can be calculated using this formula.
D = 0.5 * Speed of Sound * ( t );
t = smallest measurable time increment in micro
seconds;
D = 0.5 * 344 * (0.000001) *t = 0.000172
meters=0.0172 centimetres