Upload
noli-bellen-rafallo
View
11.774
Download
0
Embed Size (px)
DESCRIPTION
Philrobotic's first seminar for the year 2013. This is basically an introduction to Philrobokit Anito and its programming.
Citation preview
Getting started with PhilRoboKit
Anito BoardJanuary 19, 2013
Giancarlo Acelajado
Software/Firmware Developer
OBJECTIVES• Understand what PhilRoboKit Anito is.• Learn how to program PhilRoboKit Anito.
– configure a Pin– write output state– read input state– read analog input– using built-in components
• Blinking LED• Input Switch• Controlling Buzzer• Serial Communication (UART)
• An open-source Microcontroller development kit powered by Microchip PIC16F877A**beta.
• 100% Filipino-made by PhilRobotics.• Arduino-inspired project.• Programming made-easy built-in functions• Multiplatform programming IDE.• Programmable using built-in bootloader(tinybldr)
or PICKit2 through ICSP.• Uses Microchip XC8 Compiler (with Redisitribution agreement)
Who is PhilRoboKit Anito?
Specifications:
• up to 21 Digital I/Os (14 at default)
• 7 Analog-to-Digital Pins
• built-in 4 LEDs
• built-in 2 switches
• built-in buzzer
• 1 Servo Port, UART Port and Programming(ICSP) Port
• USB-to-TTL connection
Who is PhilRoboKit Anito?
Who is PhilRoboKit Anito?
Who is PhilRoboKit Anito?
The PhilRoboKit IDE
The PhilRoboKit IDE
• Code Folding• AutoComplete• Line Numbers• Find/Replace Tool• PICKit2 Support with Bootloader Recovery• Import Hex file (Flash and Bootload Programming)
• Library Imports• Load Examples• Serial Monitor
The PhilRoboKit IDE
My First PhilRoboKit ‘HelloWorld’ Program
Getting Started:
//Hitech C
#include <htc.h>
void main(void)
{
TRISC &= ~0x01;
PORTC |= 0x01;
while(1)
{
rc0 = ~rc0
__delay_ms(500);
}
}
//PhilRoboKit
void init()
{
makeOutput(D0);
setPin(D0);
}
void program()
{
togglePin(D0);
delayMs(500);
}
• Init() – where initializations are placed.
• Program() – main loop program.
Getting Started:
void init()
{
/* Statement here */
}
void program()
{
/* Statement here */
}
Getting Started:
• Digital IO Pins:– D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11,
D12, D13
• Analog Input Pins:– AN0, AN1, AN2, AN3, AN4, AN5, AN6– Configurable to Digital IOs (D14 to D20)
• makeInput(x) – configures a pin to Input
• getPinState(x) – get the state/logic of a pin whether it is HIGH(1) or LOW(0).
Basic IO Interface - Inputs
• makeOutput(x) – configures a pin to Output
• setPin(x) – set Output Pin to HIGH(1)
• clrPin(x) – set Output Pin to LOW(1)
• togglePin(x) – Toggles Output Pin (invert its previous state)
Basic IO Interface
• setADCPinsToDigital() – Sets your Analog Input Pins as Digital Input/Output.
Basic IO Interface
Note:
Initial state of Digital Outputs are Low.
All pins are 5v Tolerant.
Basic IO Interface
• Software Delay – waste instruction cycles. Used in a non-critical timing requirement.
• Hardware Delay – uses Timer peripheral. Used in time critical requirement.
Generating Delay
Generating Delay - Software Delay
void init()
{
makeOutput(D0);
setPin(D0);
}
void program()
{
togglePin(D0);
delayMs(500);
}
Generating Delay - Hardware Delay
uint16_t ui16ToggleTimer; /* Create a Timer Variable */
void init()
{
makeOutput(D0); /* Configure D0 as Output */
setPin(D0); /* Initialize D0 as HIGH */
ui16ToggleTimer = getMs(); /* Initialize Timer */
}
void program()
{
if(getElapsedMs(ui16ToggleTimer) >= 500){
ui16ToggleTimer = getMs();
togglePin(D0);
}
}
Using built-in Peripherals
Using built-in Peripherals
• Composed of:• 4 LEDs• 2 Switches• 1 Buzzer• Analog-to-Digital Converter Port• USB-to-UART Connectivity
• Pre-initialized pin directions
Using LEDs
void init()
{
}
void program()
{
setPin(LED1);
setPin(LED2);
clrPin(LED3);
clrPin(LED4);
}
Using Switches
void init()
{
}
void program()
{
if(!getPinState(SW1)){
/* Do Something here */ }
if(getPinState(SW2)){
/* Do Something here */ }
}
• HIGH at initial state – with pull up resistor.
• “Active Low” – outputs LOW when pressed.
Using Buzzer
void init()
{
}
void program()
{
setPin(BUZZER);
}
• LOW at initial state.• Turn on by setting it HIGH.
• Stands for Analog-to-Digital Converter• Converts Analog Signals (voltage or current) into
Digital format (1’s and 0’s).• 7 ADC Channels (AN0-AN7)• 10bit ADC Resolution(210-1)• 5v Internal Voltage Reference
What is ADC?
ferenceVoltage
nsolutionADC
VoltagePin
ADCValue
Re
1)^2(Re
What is ADC?
• setupADC() – setups the ADC Peripheral/module.• adcSetChannel() – select channel needed to be read.• adcStart() – start the ADC conversion (used in
conjunction with adcReadOnly).• adcReadOnly() – Reads the ADCValue (used in
conjunction with adcStart).• adcRead() – directly reads the pin, and wait for the
conversion to be finished, returns ADCValue.• adcReadOnChannel(x) – combination of adcSetChannel
and adcRead.• isADCConversionDone() – used to check/poll if the
conversion is already done.
What is ADC?
uint16_t ui16ADCValue;
void init()
{
setupADC();
adcSetChannel(AN0);
}
void program()
{
ui16ADCValue = adcReadOnChannel(AN0);
}
• Universal Asynchronous Receiver/ Transmitter• No clock signal required on data transmission• Simplest Serial Communication Interface• Used in conjunction with RS232, RS422 or
RS485
What is UART?
• Start– Signal to begin the transmission. – High to Low transition
• Data Bits– May compose 5-9 bits.– Usually in 8bits.
• Parity (optional)– Parity bit is added to ensure that the number of “active” bits in a frame is even or odd, depending on your settings.
• Stop– Signal to end the transmission– Low to High transition
What is UART?
• setupSerial(x) – setup the serial and its baudrate.• serialSendChar(x) – sends 1 byte/character• serialSendString(x) – sends a series of characters• serialSendBlock(x,y) – sends block characters with
defined size/count.• serialRead() – Read the received character from the
buffer.• isSerialDataAvailable() – checks if there’s a data
available in buffer• serialFlushData() – clears/reset the contents of the
Transmit and Receive Buffer.
What is UART?
//PhilRoboKit
void init()
{
serialSetup(9600);
}
void program()
{
serialSendString(“Hello World!\r\n”);
}
What is UART?
Questions?Questions?
References
• Hardware Manual:
• Firmware Manual:
Online Reference in wiki and Document Generated by Doxygen
• Software Manual:
Online Reference in wiki and Document Generated by Doxygen
• PhilRobotics Forum:
http://philrobotics.com/forum/index.php/board,14.0.html
• PhilRobotics Bugzilla(Issue Tracker):
http://philrobotics.com/bugzilla