pic16F628


Results 1 to 5 of 5

Thread: pic16F628

Threaded View

  1. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: pic16F628

    Hello Daydream,
    Mostly this code demonstrates why "copy/paste" does not work well for newbies, example:
    Code:
    DE@ DEVICE pic16F628
    @ DEVICE pic16F628, HS_OSCFINE OSC 10
    So allow me to direct you to threads which will help you.
    http://www.picbasic.co.uk/forum/showthread.php?t=543

    the above thread explaines the first 6 lines of your code.

    BTW this code as listed probably will not work due to errors in those 6 lines, and those 6
    lines will only work in PBP 2.6 and below, as PBP 3. does not support
    PB assembler, only MPASM(read the listed thread carefully).

    now the lcd defines
    I will comment the code you listed so as to facilitate your understanding,
    BTW this IS IN THE BOOK.
    Code:
    DEFINE LCD_DREG PORTA ' use port a for LCD
    DEFINE LCD_DBIT 0         ' first data bit on porta.0
                                         ' D4 or LCD pin 11
                                         ' so PortA.1 = D5, A.2 = D6,A.3=D7
    DEFINE LCD_RSREG PORTB 'LCD RS reg is on port B
    DEFINE LCD_RSBIT 2         'use PortB.2 as rs bit Pin4 on LCD
    define LCD_RWREG PORTB'LCD RW register is port B define should be ALLCAPS
    DEFINE LCD_RWBIT 1        'use PORTB.1 as read/write bit pin 5on LCD 
    DEFINE LCD_EREG PORTB  'use PORTB as E register
    DEFINE LCD_EBIT 0         'use PORTB.0 for e bit pin 6 on LCD
    DEFINE LCD_BITS 4'tells compiler you are using 4 bit data
                               'you could be using 8 or a whole port
    
    DEFINE LCD_LINES 2 ' this is more confusing a typical 4 line LCD is really a 2 line
                                  ' cut in half and stacked together
    
    DEFINE LCD_COMMANDUS 4000 ' 4000 micro second delay
    DEFINE LCD_DATAUS 250         '250 micro second data delay
    TRISA=0                                 'sets all of portA to output status
    TRISB=%00111100' sets PortB.2:5 to input status
    'error as portb.2 should be an output
    
    fout var word ' make word variable named fout
    foutL var fout.byte0  'alias fout lower byte as foutL
    foutH var fout.byte1  'alias fout upper byte as foutH
    
    mode var byte  'create byte variable named mode
    Delay VAR WORD 'create word variable named Delay
    Delay_Us var WORD'create word variable named Delay_Us
    x var word 'create word variable named x
    tenth var byte 'create word variable named tenth
    Z VAR BIT'use up a byte to create a bit variable named Z
    '-------------------------------------------------------------------
    Z=0' set value (initalize) bit variable to zero 
    CMCON=7 'turn OFF analog comparators 
    mode=0 ' set value (initalize) byte variable named mode to zero
    Last edited by Archangel; - 3rd May 2012 at 15:28.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts