//////////////////////////////////// // clock AND protoThreads configure! // You MUST check this file! #include "config.h" // threading library #include "pt_cornell_1_2.h" //////////////////////////////////// // graphics libraries #include "tft_master.h" #include "tft_gfx.h" // need for rand function #include //////////////////////////////////// /* Demo code for interfacing TFT (ILI9340 controller) to PIC32 * The library has been modified from a similar Adafruit library */ // Adafruit data: /*************************************************** This is an example sketch for the Adafruit 2.2" SPI display. This library works with the Adafruit 2.2" TFT Breakout w/SD card ----> http://www.adafruit.com/products/1480 Check out the links above for our tutorials and wiring diagrams These displays use SPI to communicate, 4 or 5 pins are required to interface (RST is optional) Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution ****************************************************/ //KX122 addresses #define ACCEL_XOUT_L 0x06 #define ACCEL_XOUT_H 0x07 #define ACCEL_YOUT_L 0x08 #define ACCEL_YOUT_H 0x09 #define ACCEL_ZOUT_L 0x0A #define ACCEL_ZOUT_H 0x0B #define CNTL1 0x18 #define FFCTL 0x2E #define FFTH 0x2C #define FFC 0x2D #define ODCNTL1 0x1B #define INC4 0x1F #define INC1 0x1C #define LP_CTL 0x35 #define INT_REL 0x17 //#pragma config JTAGEN = OFF, DEBUG = OFF // string buffer char buffer[60]; // === thread structures ============================================ // thread control structs

// note that UART input and output are threads static struct pt pt_timer, pt_rest, pt_fall ; // system 1 second interval tick int sys_time_seconds; volatile float x, y, z; //define

//init INT flags and ISR's volatile int FF = 0; volatile int FS = 0; volatile int t=0; void __ISR(_EXTERNAL_1_VECTOR, ipl2) C1Handler(void){ FS = 1; INTClearFlag(INT_INT1); } void __ISR(_EXTERNAL_0_VECTOR, ipl2) C1Handle(void){ FF = 1; t=PT_GET_TIME(); INTClearFlag(INT_INT0); } void initSPI(void){ /* Steps: * 1. Setup SS as digital output. * 2. Map SDO to physical pin. * 3. Configure SPI control and clock with either of a or b: * a. OpenSPIx(config1, config2) and SpiChnSetBrg(spi_channel, spi_brg) * b. SpiChnOpen(spi_channel, config, spi_divider) */ // set SS = 1 to deselect slave PPSOutput(2, RPB5, SDO2); // map SDO2 to RB5 PPSInput(3,SDI2,RPB13); //SPI pins /////// #define config1 SPI_MODE8_ON | SPI_CKE_ON | MASTER_ENABLE_ON //put SPI in 8-bit mode because accel has 8-bit registers #define config2 SPI_ENABLE /* SPI_ENABLE -> Enable SPI module */ //spen SPI OpenSPI2(config1, config2); // see pg 193 in plib reference } //SPI functions for reading and writing registers on the KX122 void WriteRegister(char thisRegister, char thisValue){ int junk; mPORTBClearBits(BIT_4);// select slave device while (TxBufFullSPI2()); // ensure buffer is free before writing WriteSPI2(thisRegister); // send the data through SPI while (SPI2STATbits.SPIBUSY); // blocking wait for end of transaction junk=ReadSPI2(); WriteSPI2(thisValue); while (SPI2STATbits.SPIBUSY); junk=ReadSPI2();// blocking wait for end of transaction mPORTBSetBits(BIT_4); // deselect slave device, transmission complete

} char ReadRegister(char ThisRegister){ char val; int junk; mPORTBClearBits(BIT_4); while (TxBufFullSPI2()); // ensure buffer is free before writing ThisRegister=(ThisRegister | 0b10000000); WriteSPI2(ThisRegister); while (SPI2STATbits.SPIBUSY); // blocking wait for end of transaction junk = ReadSPI2(); WriteSPI2(junk); while (SPI2STATbits.SPIBUSY); val=ReadSPI2(); mPORTBSetBits(BIT_4); return val; } static PT_THREAD (protothread_fall(struct pt *pt)){ int c; c = PT_GET_TIME(); PT_BEGIN(pt); PT_YIELD_TIME_msec(2000) if (FF==1){//engine to check for multiple successive FF, if yes dont call FF=0; PT_EXIT(pt);//exit thread } mPORTBSetBits(BIT_10);//INITIATE FIRST CALL while(1){ //wait 35 secs to send the call and for person to press button if ((PT_GET_TIME()-c)>35000){//if button not pressed, initiate second call mPORTBSetBits(BIT_11);//SECOND call PT_YIELD_TIME_msec(10);//10 ms for arduino to register INT mPORTBClearBits(BIT_11);//clear both pins mPORTBClearBits(BIT_10); PT_EXIT(pt); } else if (FS == 1){ //if button pressed clear bit and exit thread mPORTBClearBits(BIT_10); FS=0; PT_EXIT(pt); } } PT_END(pt); }

static PT_THREAD (protothread_rest(struct pt *pt)) { char values[3]; PT_BEGIN(pt);

while(1) { // get acceleration values, wasnt needed in final product values[0]=ReadRegister(ACCEL_XOUT_H); values[1]=ReadRegister(ACCEL_YOUT_H); values[2]=ReadRegister(ACCEL_ZOUT_H); //} float x=(float)(values[0]*2*.0156); float y=(float)(values[1]*2*.0156); float z=(float)(values[2]*2*.0156); float G=x*x+y*y+z*z; if (FF==1){//if freefall detected FF=0;//reset flags FS=0; //spawn fall thread PT_SPAWN(pt,&pt_fall, protothread_fall(&pt_fall)); } else if (FS==1){//if FS button presssed while not in spawn thread //go to spawn thread FS=0;//reset INT flags FF=0; PT_SPAWN(pt,&pt_fall, protothread_fall(&pt_fall)); } PT_YIELD_TIME_msec(10);//100 times a second } PT_END(pt); } // === Main ====================================================== void main(void) { INTEnableSystemMultiVectoredInt(); ANSELA = 0; ANSELB = 0; initSPI();//obvious //make appropriate pins inputs/outputs for SPI and arduino communication mPORTBSetPinsDigitalOut(BIT_4); mPORTBSetPinsDigitalOut(BIT_11); mPORTBClearBits(BIT_11); mPORTBSetPinsDigitalOut(BIT_10); mPORTBClearBits(BIT_10); mPORTBSetPinsDigitalIn(BIT_7); mPORTBSetPinsDigitalIn(BIT_9); PPSInput(4,INT1,RPB9); mPORTASetPinsDigitalIn(BIT_3); //config failsafe button Ex INT DisableINT1; ConfigINT1(EXT_INT_ENABLE | FALLING_EDGE_INT | EXT_INT_PRI_2); INTClearFlag(INT_INT1); EnableINT1; //config EX INT for freefall line DisableINT0; ConfigINT0(EXT_INT_ENABLE | RISING_EDGE_INT | EXT_INT_PRI_2);

INTClearFlag(INT_INT0); EnableINT0; // === config threads ========== // turns on PT PT_setup(); // === setup system wide interrupts ========

/////////////////////////////////////////////////////// // init the accelerometer WriteRegister(CNTL1, 0x08);//sets range to 4g and accel to config & low power mode WriteRegister(ODCNTL1, 0x01);//sets odr to 12.5hz WriteRegister(LP_CTL, 0x30);//sets to low power mode averaging WriteRegister(FFCTL, 0xC0);//enables free fall engine WriteRegister(INC1, 0xF8);//puts interrupt to pulse mode anf output to pin WriteRegister(INC4, 0x80);//latches FF int to INT1 pin WriteRegister(FFTH, 0x0A);//sets FF g threshold to 10 counts WriteRegister(FFC, 0x02);//sets FF time threshold to 160 ms ReadRegister(INT_REL);//clears the INT pin just incase WriteRegister(CNTL1, 0x88);//puts the accel in run mode //init thread PT_INIT(&pt_rest);

while(PT_GET_TIME()<4100);//quick delay to avoid any pins being set high on startup and triggering the call // round-robin scheduler for threads while (1){ //tft_fillScreen(ILI9340_BLACK); PT_SCHEDULE(protothread_rest(&pt_rest)); } } // main // === end ======================================================



PIC code .pdf

system 1 second interval tick. int sys_time_seconds;. volatile float x, y, z;. //define. //init INT flags and ISR's. volatile int FF = 0;. volatile int FS = 0;. volatile int t=0;. void __ISR(_EXTERNAL_1_VECTOR, ipl2) C1Handler(void){. FS = 1;. INTClearFlag(INT_INT1);. } void __ISR(_EXTERNAL_0_VECTOR, ipl2) C1Handle(void){.

119KB Sizes 4 Downloads 228 Views

Recommend Documents

PIC code .pdf
please support Adafruit and open-source hardware by purchasing. products from Adafruit! Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all ...

PIC book
Files created as a result of program translation. Macros. CHAPTER .... becomes very popular, so it was installed into computers such as: KIM-1, Apple I, Apple II,.

PIC book
PIC microcontrollers; low-cost computers-in-a-chip; allows ..... PIC16F84 perfectly fits many uses, from automotive industries and controlling home appliances to ...... MikroElektronika Internet presentation using options copy and paste.

pic microcontroller project book pdf
pic microcontroller project book pdf. pic microcontroller project book pdf. Open. Extract. Open with. Sign In. Main menu. Displaying pic microcontroller project ...

pic microcontroller 16f877a tutorial pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. pic microcontroller 16f877a tutorial pdf. pic microcontroller 16f877a tutorial pdf. Open. Extract. Open with

Nice Pic Email.pdf
From: Russ Racop fmailto:russracopfaatt.net1. Sent: Tuesday, August 05, 2014 10:08 PM. To: Dan McDonald. Cc: [email protected]. Subject: Flyers. Flyers to be distributed this week. Russ Racop. 301 Alamo Drive. Little Rock, AR 72211. 501-3

the pic microcontroller book pdf
Click here if your download doesn't start automatically. Page 1 of 1. the pic microcontroller book pdf. the pic microcontroller book pdf. Open. Extract. Open with.

Abigaile johnson pic
The greatst trinians train robbery. ... migrant workers unrealisticambitions but he does showhowconditions during the Great Depression ... Warfare history pdf.

PIC Minutes-Oct4-2016.pdf
FWC has been supported in past for translation. ○ Social Media Initiative. Page 3 of 5. PIC Minutes-Oct4-2016.pdf. PIC Minutes-Oct4-2016.pdf. Open. Extract.

PIC Minutes -Oct20-2015.pdf
... Moved by Laura Cater, seconded by Mark Savenkoff. Carried. f) Events Update (Cathy). The list of events is on the CSPA website, using PRO Regional Grant and PIC funds. to put on events in the region. Events were touched upon, live streaming for p

pic microcontroller 16f877a tutorial pdf
pic microcontroller 16f877a tutorial pdf. pic microcontroller 16f877a tutorial pdf. Open. Extract. Open with. Sign In. Main menu. Displaying pic microcontroller ...

dienhathe.com-selec-pic-1000_user_manual.pdf
Press +. Range: 1 / 0.1 for TC / RTD. 1 / 0.1 / 0.01 / 0.001 for AIN. Display for 1sec. Default value: 1. NOTE: This parameter is not prompted if input is R, S type thermocouple. Resolution. Press key to select Resolution. Default value: 1sec. Press

dienhathe.com-selec-pic-1000_user_manual.pdf
Display scaling. (low). Input s alin c g. (low). p Dis lay scaling. ( h hig ). Input scaling. (high). r Reve se scaling. S P Hig it . . h lim. P w S. . Lo limit. No of Progr ms . a. Reset. INPUT PARAMETERS. o m b r Pr gra num e. ( to scroll through f

Q1 2005 revised with pic
course they advocate, should contact the Management Committee and let .... Dell Computer to back up the records of the TTFNC. ..... E-mail: [email protected]).

alexis texas pic set.pdf
Free desktop wallpapers 3/11/07 3/18/07. Obesetexas girlalexis shapiro loses 6lbsand offinsulin after. News roomcommunities in schools ofsouth centraltexas.

ocsb-pic-procedural-bylaws.pdf
Page 2 of 9. TABLE OF CONTENTS. PROCEDURAL BY-LAWS. Page. Education Act i. Purpose ii. By-Law. Number. Description. 1 Composition of Committee / Appointment or Election. of Members. 1. 2 Term of Office / Vacancies 2. 3 Chairperson / Spokesperson 3. 4

ocsb-pic-fact-sheet.pdf
Page 1 of 1. Supporting Parent Engagement in Ontario. School Boards and Schools. All boards in Ontario are required to have a Parent Involvement. Committee by February 2011. This fact sheet answers commonly. asked questions about Parent Involvement C

PIC Serial Communication Tutorial (UART ... -
Mar 29, 2012 - PIC Countdown Timer (0-99) ... a 00-99 min programmable timer. ... would produce a relatively large code if performed on the library level.

PIC Serial Communication Tutorial (UART ... -
Mar 29, 2012 - Find us on Facebook. Embedded Projects. Like ... Facebook social plugin. Email address. .... Projects Topic (1). Real Time Monitoring (2).

PIC Microcontrollers - Programming in C.pdf
2 Apr 2017 - 43551 -- 48926 -- -- -- -- -- -- -- 40895 -- 29657 -- 40875 54352 -- -- -- -- --. Whoops! There was a problem loading this page. Retrying... PIC Microcontrollers - Programming in C.pdf. PIC Microcontrollers - Programming in C.pdf. Open.

519 Ethiopia Report with pic
and ethno-linguistic system of classification in Ethiopia is ...... ing, little food or medical treatment. ...... See also Morrison, J.S., 'Ethiopia charts a new course',.

Interfacing PIC Microcontrollers Embedded Design by Interactive ...
Interfacing PIC Microcontrollers Embedded Design by Interactive Simulation.pdf. Interfacing PIC Microcontrollers Embedded Design by Interactive Simulation.pdf.

Abstract-Template_2nd PIC UMP.pdf
William Levine Hall-Ernest Mario School of Pharmacy, Rutgers University, 160 Frelinghuysen Road, Piscataway, NJ,. USA; 2Department of Pharmacy, National ...