Compiled OK with line...
pbpw -p16f876a sample -v
Lots of embedded comments to tell you what's happening...
Enjoy
Code:' Sample.BAS ' ========== ' Target Processor PIC16F876A-04 ' ' Write value '1234' to internal EEPROM ' When Button Pressed Read EEPROM value and Display on LCD ' ' ' CPU Hardware Layout ' ------------------- ' ' PortA.0 - Unused - Set to INPUT ' PortA.1 - Unused - Set to INPUT ' PortA.2 - Unused - Set to INPUT ' PortA.3 - Unused - Set to INPUT ' PortA.4 - Unused - Set to INPUT ' PortA.5 - Unused - Set to INPUT ' ' PortB.0 - Button - Connect between this PIC Pin and Vss (0v) ' - uses internal PICs pull-up's ' PortB.1 - Unused - Set to OUTPUT ' PortB.2 - LCD - RS ' PortB.3 - LCD - E ' PortB.4 - LCD - DB4 ' PortB.5 - LCD - DB5 ' PortB.6 - LCD - DB6 ' PortB.7 - LCD - DB7 ' ' PortC.0 - Unused - Set to OUTPUT ' PortC.1 - Unused - Set to OUTPUT ' PortC.2 - Unused - Set to OUTPUT ' PortC.3 - Unused - Set to OUTPUT ' PortC.4 - Unused - Set to OUTPUT ' PortC.5 - Unused - Set to OUTPUT ' PortC.6 - Unused - Set to OUTPUT ' PortC.7 - Unused - Set to OUTPUT ' ' PIC Defines ' ----------- @ DEVICE pic16F876A, XT_OSC ' System Clock Options @ DEVICE pic16F876A, WDT_ON ' Watchdog Timer @ DEVICE pic16F876A, PWRT_ON ' Power-On Timer @ DEVICE pic16F876A, BOD_ON ' Brown-Out Detect @ DEVICE pic16F876A, LVP_OFF ' Low-Voltage Programming @ DEVICE pic16F876A, CPD_OFF ' Data Memory Code Protect @ DEVICE pic16F876A, PROTECT_OFF ' Program Code Protection @ DEVICE pic16F876A, WRT_OFF ' Flash Memory Word Enable ' ' Hardware Defines ' ---------------- ' ' LCD Display ' ----------- Define LCD_DREG PORTB ' Port for LCD Data Define LCD_DBIT 4 ' Use upper 4 bits of Port Define LCD_RSREG PORTB ' Port for RegisterSelect (RS) bit Define LCD_RSBIT 2 ' Port Pin for RS bit Define LCD_EREG PORTB ' Port for Enable (E) bit Define LCD_EBIT 3 ' Port Pin for E bit Define LCB_BITS 4 ' Using 4-bit bus Define LCD_LINES 2 ' Using 2 line Display Define LCD_COMMANDUS 2000 ' Command Delay (uS) Define LCD_DATAUS 50 ' Data Delay (uS) ' ' Button Inputs ' ------------- ButtonPRESS var PortB.0 ' Push Button ' ' EEPROM ' ------ MemoryA DATA @0,0 ' The TWO memory locations for saving WORD variable MemoryB DATA 0 ' Both Preset to Zero ' ' RAM Assignments & Variables ' --------------------------- WORDVariable var WORD ' Just a WORD variable we're going to use ' ' Start Program ' ============= ' ' Set-up Hardware ' --------------- TRISA=%00111111 ' All available PortA is Input ' Remember it's still in ANALOG Mode TRISB=%00000001 ' All PortB is Output - except ' B.0 = Button TRISC=%00000000 ' All PortC is Output CMCON=%00000111 ' Disable Comparators CVRCON=%00000000 ' Disable Reference Module OPTION_REG.7=0 ' Enable Weak Pull-Up's Pause 2000 ' Wait for LCD to settle ' ' Save Value into EEPROM ' ----------------------- WORDVariable=1234 LCDOut $FE,1,"Writing=",#WordVariable ' Tell user what we're doing... WRITE MemoryA,WORDVariable.HighByte ' Save one Byte from Word to EEPROM Location 0 WRITE MemoryB,WORDVariable.LowByte ' Save other Byte from Word to EEPROM Location 1 Pause 2000 ' Just a pause so you can read what's on the LCD ' ' Prompt for Button Press ' ----------------------- PromptLoop: LCDOut $FE,1,"Press Button..." While ButtonPRESS=1:Wend ' Wait here until Button Pressed READ MemoryA,WORDVariable.HighByte ' Reconstruct Word variable from EEPROM READ MemoryB,WORDVariable.LowByte LCDOut $FE,1,"Reading=",#WORDVariable ' Display Result While ButtonPress=0:Wend ' Wait here as long as finger is on Button Goto PromptLoop ' End




Bookmarks