Week-8
Embedded Programming
Assignment
1. Read a micro controller data sheet
2. Program board to do something, with as many different programming languages
and programming environments as possible.
3.Programing a RGB board for fleshing light.
Reading a micro controller data sheet
I started reading a micro controller data sheet. First of all I read it but I didn't understand anything in one go. But I tried reading it again and again and started understanding slowly. This is the first time I am opening a micro-controller data sheet.
It was boring at first time reading it. I didn't know what I was actually ready. It was like I am reading some alien language.
Later after reading the micro-controller data sheet for some time (more than 7/8 hours), now I am understanding why we need to read it.
The data sheet can be downloaded from the link .
The data sheet had few things which I didn't know and was very useful to me.
These are few things that were useful to me recently for my understanding.
Program your board to do something :
I selected hello.arduino.328P for do this exercise.
I wanted to learn and understand arduino programming through C/C++ language.
Now its turn to mill the board and start working with it.
Steps involved are :
1. Milling the board
2. Soldering the components
3. Programming of the board through Arduino
Step-1 : Milling the board
The file is selected from the fab module page link.
This is the circuit diagram of the board hello.arduino.328 :
Complete board with all the components
Screen shots of the milling process:
Pictures of the process:
Step-2 : Soldering of the board
Components used for the board:
I wanted to understand how the coding works and what are the components that can make the board.
So I wanted to first list all the components for the board.
Once all the components are ready I started soldering components one by one.
First time I over heated the micro controller so had to mill another board and start soldering again.
Step-3 : Programming of the board
Once the board is ready I started coding. I am using Arduino uno for the coding of the board.
The circuit is made and now the Arduino Uno is connected to the computer.
Once the board is connected upload the basic empty sketch from the new file and upload it.
For uploading the file in uno there is a way to go about.
Once the tab is open go to TOOLS and select Board ------ Arduino/Genuino Uno.
Also check the COM port from the tools tab.
Now once all set with these options press the arrow button from on the left side of the window and upload the sketch to the uno.
After all the process now see if the code is uploaded. If the code will be uploaded you will see the window like this:
DONE UPLOADING saying the space used by the program in the micro controller.
Once the basic code is uploaded so far there is no issue in the program. Now take the board that we have made and connect the board to the arduino.
Note I am using Old style wiring so the code given in fab archive will have different pin numbers.
Connection rules: See the circuit diagram of the board and identify the pins that we have to connect with the arduino.
Colour code for the connection of six pins from the board
GND- ORANGE
MOSI - RED
V - WHITE
RST - YELLOW
SCK - GREEN
MISO - BLACK
Now this 6 pins are connected to the Arduino board.
PIN_MOSI to 11
PIN_MISO to 12
PIN_SCK to 13
PIN_RST to 10
GND to ground of arduino
V to 5v of arduino
Once the connections are done the board would look like:
After connecting the board with arduino now its time to upload the sketch in arduino and the board. Open the arduino window and now from the tools option:
Go to BOARD - select Arduino Pro or Mini
Go to PROGRAMMER - select Arduino as ISP
Now open File - go to EXAMPLES - select 11. ArduinoISP
And load the sketch. This will make the arduino board work like a AVR programmer.
Once the arduino is converted to programmer now upload the code for the hello arduino 328 board that we are working on.
You can get the code directly from the site. Link This code will be boot loaded to the board
Once the code it uploaded you can see the light blink once.
Now upload the CODE to the board again and see the blinking of the board according to the delay.
Once I FINISHED PROGRAMING THE hello.arduino.328P board then I took my Echo Hello world board that I made in Week 6.
I wanted to program the board through Arduino board:
The process of coding starts again. I have coded the board in the same way that I DID FOR HELLO.ARDUINO BOARD.
The process of coding starts again. I have coded the board in the same way that I DID FOR HELLO.ARDUINO BOARD.
This is the code that I tried to work:
#include <avr/io.h>
#include <util/delay.h>
#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= (~pin)) // set port direction for input
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define bit_delay_time 102 // bit delay for 9600 with overhead
#define bit_delay() _delay_us(bit_delay_time) // RS232 bit delay
#define half_bit_delay() _delay_us(bit_delay_time/2) // RS232 half bit delay
#define input_port PORTB
#define input_direction DDRB
#define input_pin (1 << PC6)
#define input_pins PINB
int main(void) {
//
// main
//
// set clock divider to /1
//
CLKPR = (1 << CLKPCE);
CLKPR= (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
//
// initialize pins
//
set(input_port, input_pin); // turn on pull-up
input(input_direction, input_pin);
//
// main loop
//
while (1) {
//
// wait for button down
//
while (0 != pin_test(input_pins,input_pin))
;
digitalWrite(PB5, HIGH);
//
// wait for button up
//
while (0 == pin_test(input_pins,input_pin))
;
digitalWrite(PB5, LOW);
}
}
LED Blinks when I press the button
RGB LED with a Button
Step-1 :Programing the board
The programing of the board is done through Arduino Board:
First the Arduino board is made as Programmer and then the program for the RGB led is uploaded
Step-2 :Result from the board
Button_Blinking_RED_Light
Button_Blinking_Yellow_Red_Green