Mgr. Vojtěch KrmíčekMgr. Vojtěch Krmíček vojtec@ics.muni.czvojtec@ics.muni.cz Ing. Zbyněk BurešIng. Zbyněk Bureš, Ph.D., Ph.D. zbynek.bureszbynek.bures@@unobunob..czcz PIC12FPIC12F629 / 675629 / 675 Programming PIC in C Part IIProgramming PIC in C Part II Inline AssemblerInline Assembler EEPROMEEPROM Inline AssemblerInline Assembler Two variants:Two variants: unsigned int var; #asm bcf 0,3 rlf _var rlf _var+1 #endasm // or like this asm(“bcf 0,3”); asm(“rlf _var”); asm(“rlf _var+1”); A #asm block can't be used within any C constructsA #asm block can't be used within any C constructs such as if, while, do...such as if, while, do... Timing FunctionsTiming Functions Frequency of oscillator must be defined: #define _XTAL_FREQ 4000000 Two functions: __delay_ms(x) // request a delay in milliseconds __delay_us(x) // request a delay in microseconds PackagePackage EEPROM - basicsEEPROM - basics Readable and writable duringReadable and writable during normal voltage,normal voltage, memory is not directly accessible,memory is not directly accessible, it’s mapped in the register file space,it’s mapped in the register file space, direct access via C functionsdirect access via C functions:: eeprom_write()eeprom_write() eeprom_read()eeprom_read() address range from 0h to 7Fhaddress range from 0h to 7Fh interrupt on write complete (EEIF)interrupt on write complete (EEIF) Functions for Accessing EEPROM IFunctions for Accessing EEPROM I eeprom_write() initiates process of writingeeprom_write() initiates process of writing to the EEPROM memory and returns whento the EEPROM memory and returns when write is completedwrite is completed new data in EEPROM are valid approx.new data in EEPROM are valid approx. 4ms later ( = 4000 instruction cycles!)4ms later ( = 4000 instruction cycles!) but next read/write operation waits untilbut next read/write operation waits until previous one is finishedprevious one is finished Functions for Accessing EEPROM IIFunctions for Accessing EEPROM II #include void eetest(void){ unsigned char value = 1; unsigned char address = 0; eeprom_write(address,value); // Initiate writing value to address value = eeprom_read(address); // read from EEPROM at address } EEPROM RegistersEEPROM Registers