Login:
Stimmen - 2, Durchschnittliche Bewertung: 4.5 ( )

Anleitung ABL electronic, modell PIC Microcontrollers PIC18

Hersteller: ABL electronic
Dateigröße: 1.34 mb
Dateiname:
Unterrichtssprache:en
Link zum kostenlosen Download Hinweise finden Sie am Ende der Seite



Anleitung Zusammenfassung


Flash Memory Library This library provides routines for accessing microcontroller Flash memory. Note that prototypes differ for PIC16 and PIC18 families. Library Routines Flash_Read Flash_Write Flash_Read Prototype unsigned Flash_Read(unsigned address); // for PIC16 char Flash_Read(long unsigned address); // for PIC18 Returns Returns data byte from Flash memory. Description Reads data from the specified address in Flash memory. Example Flash_Read(0x0D00); Flash_Write Prototype void Flash_Write(unsigned address, unsigned data); // for PIC16 void Flash_Write(unsigned long address, char *data); // for PIC18 Description Writes chunk of data to Flash memory. With PIC18, data needs to be exactly 64 bytes in size. Keep in mind that this function erases target memory before writing Data to it. This means that if write was unsuccessful, previous data will be lost. Example // Write consecutive values in 64 consecutive locations char toWrite[64]; // initialize array: for (i = 0; i < 63; i++) toWrite[i] = i; Flash_Write(0x0D00, toWrite); page MikroElektronika: Development tools -Books -Compilers 186 mikroC making it simple... mikroC - C Compiler for Microchip PIC microcontrollers Library Example The example demonstrates simple data exchange via USART. When PIC MCU receives data, it immediately sends the same data back. If PIC is connected to the PC (see the figure below), you can test the example from mikroC terminal for RS232 communication, menu choice Tools > Terminal. char i = 0, j = 0; long addr; unsigned short dataRd; unsigned short dataWr[64] = {1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0, 1,2,3,4}; void main() { PORTB = 0; TRISB = 0; PORTC = 0; TRISC = 0; addr = 0x00000A30; // valid for P18F452 Flash_Write(addr, dataWr); addr = 0x00000A30; for (i = 0; i < 64; i++) { dataRd = Flash_Read(addr++); PORTB = dataRd; Delay_ms(500); } }//~! page MikroElektronika: Development tools -Books -Compilers 187 mikroC mikroC - C Compiler for Microchip PIC microcontrollers making it simple... I2C Library I.C full master MSSP module is available with a number of PIC MCU models. mikroC provides I2C library which supports the master I.C mode. Note: This library supports module on PORTB or PORTC, and will not work with modules on other ports. Examples for PICmicros with module on other ports can be found in your mikroC installation folder, subfolder “Examples”. Library Routines I2C_Init I2C_Start I2C_Repeated_Start I2C_Is_Idle I2C_Rd I2C_Wr I2C_Stop I2C_Init Prototype void I2C_Init(long clock); Description Initializes I.C with desired clock (refer to device data sheet for correct values in respect with Fosc). Needs to be called before using other functions of I2C Library. Requires Library requires MSSP module on PORTB or PORTC. Example I2C_Init(100000); page MikroElektronika: Development tools -Books -Compilers 188 mikroC making it simple... mikroC - C Compiler for Microchip PIC microcontrollers I2C_Start Prototype char I2C_Start(void); Returns If there is no error, function returns 0. Description Determines if I.C bus is free and issues START signal. Requires I.C must be configured before using this function. See I2C_Init. Example I2C_Start(); I2C_Repeated_Start Prototype void I2C_Repeated_Start(void); Description Issues repeated START signal. Requires I.C must be configured before using this function. See I2C_Init. Example I2C_Repeated_Start(); I2C_Is_Idle Prototype char I2C_Is_Idle(void); Returns Returns 1 if I.C bus is free, otherwise returns 0. Description Tests if I.C bus is free. Requires I.C must be configured before using this function. See I2C_Init. Example if (I2C_Is_Idle()) {...} page MikroElektronika: Development tools -Books -Compilers 189 mikroC mikroC - C Compiler for Microchip PIC microcontrollers making it simple... I2C_Rd Prototype char I2C_Rd(char ack); Returns Returns one byte from the slave. Description Reads one byte from the slave, and sends not acknowledge signal if parameter ack is 0, otherwise it sends acknowledge. Requires START signal needs to be issued in order to use this function. See I2C_Start. Example temp = I2C_Rd(0); // Read data and send not acknowledge signal I2C_Wr Prototype char I2C_Wr(char data); Returns Returns 0 if there were no errors. Description Sends data byte (parameter data) via I.C bus. Requires START signal needs to be issued in order to use this function. See I2C_Start. Example I2C_Write(0xA3); I2C_Stop Prototype void I2C_Stop(void); Description Issues STOP signal. Requires I.C must be configured before using this function. See I2C_Init. page MikroElektronika: Development tools -Books -Compilers 190 mikroC making it simple... mikroC - C Compiler for Microchip PIC microcontrollers Library Example This code demonstrates use of I.C Library functions. PIC MCU is connected (SCL, SDA pins ) to 24c02 EEPROM. Program sends data to EEPROM (data is written at address 2). Then, we read data via I2C from EEPROM and se...

Dieses Handbuch ist für folgende Modelle:
PC Notebooks - PIC Microcontrollers PIC12 (1.34 mb)
PC Notebooks - PIC Microcontrollers PIC16 (1.34 mb)

Bewertungen



Bewerten
Vorname:
Geben Sie zwei Ziffern:
capcha





Kategorien