RNDr. VojtRNDr. Vojtěěchch KrmKrmííččekek vojtec@vojtec@icsics..munimuni..czcz Ing.Ing. ZbynZbyněěk Burek Burešš, Ph.D., Ph.D. zbynekzbynek..buresbures@@unobunob..czcz PIC12F629 / 675 Programming PIC in C Part II PIC12FPIC12F629 / 675629 / 675 ProgrammingProgramming PIC in CPIC in C Part IIPart II InlineInline AssemblerAssembler TwoTwo variantsvariants:: 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 constructs such as if, while, do... TimingTiming FunctionsFunctions 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 ProgrammingEEPROM Programming Readable and writable duringReadable and writable during normal voltage,normal voltage, memory is not directly accessible,memory is not directly accessible, itit''s mapped in the register file space,s mapped in the register file space, directdirect accessaccess via Cvia C functionsfunctions:: eepromeeprom__writewrite()() eepromeeprom__readread()() addressaddress rangerange fromfrom 0h to 7Fh0h to 7Fh interruptinterrupt onon writewrite completecomplete (EEIF)(EEIF) Functions for Accessing EEPROM IFunctionsFunctions forfor AccessingAccessing EEPROM IEEPROM I eepromeeprom__writewrite()() initiatesinitiates processprocess ofof writingwriting toto thethe EEPROMEEPROM memorymemory andand returnsreturns whenwhen writewrite isis completedcompleted newnew data in EEPROM aredata in EEPROM are validvalid approxapprox.. 4ms4ms laterlater ( = 4000( = 4000 instructioninstruction cyclescycles!)!) butbut nextnext readread//writewrite operationoperation waitswaits untiluntil previousprevious oneone isis finishedfinished Functions for Accessing EEPROM IIFunctionsFunctions forfor AccessingAccessing EEPROM IIEEPROM 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 }