You are on page 1of 34

Getting started with PhilRoboKit Anito Board

January 19, 2013 Giancarlo Acelajado


Software/Firmware Developer
giancarlo.acelajado@philrobotics.com

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)

Who is PhilRoboKit Anito?


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?

The PhilRoboKit IDE

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

My First PhilRoboKit HelloWorld Program

Getting Started:
//Hitech C #include <htc.h> //PhilRoboKit void init()

void main(void)
{ TRISC &= ~0x01; PORTC |= 0x01; while(1) { rc0 = ~rc0

{
makeOutput(D0); setPin(D0); }

void program() {

__delay_ms(500);
} } }

togglePin(D0);
delayMs(500);

Getting Started:
void init() { /* Statement here */

Init() where initializations are placed.

void program() { /* Statement here */ }

Program() main loop program.

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)

Basic IO Interface - Inputs

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

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.

Generating Delay

Software Delay waste instruction cycles. Used in a non-critical timing requirement. Hardware Delay uses Timer peripheral. Used in time critical requirement.

Generating Delay - Software Delay


void init() { makeOutput(D0); setPin(D0); }

void program() { togglePin(D0); delayMs(500); }

Generating Delay - Hardware Delay


uint16_t void init() { makeOutput(D0); setPin(D0); ui16ToggleTimer = getMs(); } void program() { if(getElapsedMs(ui16ToggleTimer) >= 500){ /* Configure D0 as Output */ /* Initialize D0 as HIGH */ /* Initialize Timer */ ui16ToggleTimer; /* Create a Timer Variable */

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() { }

HIGH at initial state with pull up resistor. Active Low outputs LOW when pressed.

void program()

{
if(!getPinState(SW1)){ /* Do Something here */ }

if(getPinState(SW2)){
/* Do Something here */ } }

Using Buzzer
void init() { }

LOW at initial state. Turn on by setting it HIGH.

void program()

{
setPin(BUZZER); }

What is ADC?
Stands for Analog-to-Digital Converter Converts Analog Signals (voltage or current) into Digital format (1s and 0s). 7 ADC Channels (AN0-AN7) 10bit ADC Resolution(210-1) 5v Internal Voltage Reference
ADCValue ADC Re solution(2^ n) 1 VoltagePin Voltage Re ference

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 void init() { setupADC(); adcSetChannel(AN0); ui16ADCValue;

void program() { ui16ADCValue = adcReadOnChannel(AN0); }

What is UART?
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 theres 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); }

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

You might also like