Re: Ytterligare en HD44780 tråd.....
Postat: 12 maj 2009, 17:53:46
Hmmm... jag måste nog dit med en drös med "Global" och "Extern" kommandon.
Det låter väl ganska troligt?
MVH Peter F
Det låter väl ganska troligt?
MVH Peter F
Svenskt forum för elektroniksnack.
https://elektronikforumet.com/forum/
Kod: Markera allt
; Huvud-program
;**********************************************************************
list p=16F628A ; list directive to define processor
#include <p16F628A.inc> ; processor specific variable definitions
; #include <onewire.inc>
errorlevel -302 ; suppress message 302 from list file
__CONFIG _CP_OFF & _DATA_CP_OFF & _LVP_OFF & _BOREN_OFF & _MCLRE_ON & _WDT_OFF & _PWRTE_ON & _INTOSC_OSC_NOCLKOUT
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
extern OW_RESET ;definieras i Dallas filen...
extern DSRXBYTE ;definieras i Dallas filen...
extern DSTXBYTE ;definieras i Dallas filen...
global IOBYTE
;***** VARIABLE DEFINITIONS (examples)
My_VAR UDATA_SHR
IOBYTE RES 1
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
;**********************************************************************
RESET_VECTOR CODE 0x0000 ; processor reset vector
goto START ; go to beginning of program
INT_VECTOR CODE 0x0004 ; interrupt vector location
INTERRUPT
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
; isr code can go here or be located as a call subroutine elsewhere
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
MAIN_PROG CODE
START
call ow_reset
; remaining code goes here
goto $ ; loop forever
; initialize eeprom locations
EE CODE 0x2100
DE 0x00, 0x01, 0x02, 0x03
END ; directive 'end of program'
Kod: Markera allt
; *******************************************************
;
; Dallas 1-Wire Support for PIC16F628
;
; Processor has 4MHz clock and 1µs per instruction cycle.
;
; *******************************************************
#include <p16F628A.inc>
global OW_RESET
global DSRXBYTE
global DSTXBYTE
extern IOBYTE
DQ EQU 1
My_VAR UDATA_SHR
TMP0 RES 1
PDBYTE RES 1
COUNT RES 1
; Använder PORT A
; *******************************************************
; Dallas Semiconductor 1-Wire MACROS
; *******************************************************
OW_HIZ:MACRO
BSF STATUS,RP0 ; Select Bank 1 of data memory
BSF TRISA, DQ ; Make DQ pin High Z
BCF STATUS,RP0 ; Select Bank 0 of data memory
ENDM
; --------------------------------------------------------
OW_LO:MACRO
BCF STATUS,RP0 ; Select Bank 0 of data memory
BCF PORTA, DQ ; Clear the DQ bit
BSF STATUS,RP0 ; Select Bank 1 of data memory
BCF TRISA, DQ ; Make DQ pin an output
BCF STATUS,RP0 ; Select Bank 0 of data memory
ENDM
; --------------------------------------------------------
WAIT:MACRO TIME
;Delay for TIME µs.
;Variable time must be in multiples of 5µs.
MOVLW (TIME/5)-1 ;1µs
MOVWF TMP0 ;1µs
CALL WAIT5U ;2µs
ENDM
; *******************************************************
; Dallas Semiconductor 1-Wire ROUTINES
; *******************************************************
onewire_code code
WAIT5U:
;This takes 5µS to complete
NOP ;1µs
NOP ;1µs
DECFSZ TMP0,F ;1µs or 2µs
GOTO WAIT5U ;2µs
RETLW 0 ;2µs
; --------------------------------------------------------
OW_RESET:
OW_HIZ ; Start with the line high
CLRF PDBYTE ; Clear the PD byte
OW_LO
WAIT .500 ; Drive Low for 500µs
OW_HIZ
WAIT .70 ; Release line and wait 70µs for PD Pulse
BTFSS PORTA,DQ ; Read for a PD Pulse
INCF PDBYTE,F ; Set PDBYTE to 1 if get a PD Pulse
WAIT .400 ; Wait 400µs after PD Pulse
RETLW 0
; --------------------------------------------------------
DSRXBYTE: ; Byte read is stored in IOBYTE
MOVLW .8
MOVWF COUNT ; Set COUNT equal to 8 to count the bits
DSRXLP:
OW_LO
NOP
NOP
NOP
NOP
NOP
NOP ; Bring DQ low for 6µs
OW_HIZ
NOP
NOP
NOP
NOP ; Change to HiZ and Wait 4µs
MOVF PORTA,W ; Read DQ
ANDLW 1<<DQ ; Mask off the DQ bit
ADDLW .255 ; C=1 if DQ=1: C=0 if DQ=0
RRF IOBYTE,F ; Shift C into IOBYTE
WAIT .50 ; Wait 50µs to end of time slot
DECFSZ COUNT,F ; Decrement the bit counter
GOTO DSRXLP
RETLW 0
; --------------------------------------------------------
DSTXBYTE: ; Byte to send starts in W
MOVWF IOBYTE ; We send it from IOBYTE
MOVLW .8
MOVWF COUNT ; Set COUNT equal to 8 to count the bits
DSTXLP:
OW_LO
NOP
NOP
NOP ; Drive the line low for 3µs
RRF IOBYTE,F
BSF STATUS,RP0 ; Select Bank 1 of data memory
BTFSC STATUS,C ; Check the LSB of IOBYTE for 1 or 0
BSF TRISA,DQ ; HiZ the line if LSB is 1
BCF STATUS,RP0 ; Select Bank 0 of data memory
WAIT .60 ; Continue driving line for 60µs
OW_HIZ ; Release the line for pullup
NOP
NOP ; Recovery time of 2µs
DECFSZ COUNT,F ; Decrement the bit counter
GOTO DSTXLP
RETLW 0
; --------------------------------------------------------
end
Kod: Markera allt
Message[310] C:\MICROCHIP\MPASM SUITE\P16F628A.INC 490 : Superseding current maximum RAM and RAM map.
Och
Error - could not find definition of symbol 'IOBYTE' in file './onewiretesto.o'.
Kod: Markera allt
; '__CONFIG' directive is used to embed configuration word within .asm file.
; The lables following the directive are located in the respective .inc file.
; See data sheet for additional information on configuration word settings.
extern OW_RESET ;definieras i Dallas filen...
extern DSRXBYTE ;definieras i Dallas filen...
extern DSTXBYTE ;definieras i Dallas filen...
global IOBYTE
;***** VARIABLE DEFINITIONS (examples)
; example of using Shared Uninitialized Data Section
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
IOBYTE RES 1
Kod: Markera allt
global OW_RESET
global DSRXBYTE
global DSTXBYTE
;global IOBYTE
extern IOBYTE
DQ EQU 1
My_VAR UDATA_SHR
TMP0 RES 1
PDBYTE RES 1
COUNT RES 1
Kod: Markera allt
------------- asm filen-----------------
INT_VAR UDATA_SHR
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
IOBYTE RES 1
------------- inc filen ------------------
My_VAR UDATA_SHR
TMP0 RES 1
PDBYTE RES 1
COUNT RES 1
Kod: Markera allt
MPLINK 4.30.01, Linker
Linker Error Map File - Created Tue May 12 22:40:06 2009
*Warning* - This is only a partial map file due to a link time error.
Only sections which were allocated prior to the error are shown below.
CODEPAGES:
Memory Start End Section Address Size(Bytes)
--------- --------- --------- --------- --------- ---------
page 0x0000 0x07ff
.idlocs 0x2000 0x2003
.device_id 0x2006 0x2006
.config 0x2007 0x2007
eedata 0x2100 0x217f
SHAREBANKS:
Memory Start End Section Address Size(Bytes)
--------- --------- --------- --------- --------- ---------
gprnobnk0 0x0070 0x007e
gprnobnk0 0x00f0 0x00fe
gprnobnk0 0x0170 0x017e
gprnobnk0 0x01f0 0x01fe
gprnobnk1 0x007f 0x007f
gprnobnk1 0x00ff 0x00ff
gprnobnk1 0x017f 0x017f
DATABANKS:
Memory Start End Section Address Size(Bytes)
--------- --------- --------- --------- --------- ---------
sfr0 0x0000 0x001f
sfr1 0x0080 0x009f
sfr2 0x0100 0x010b
sfr3 0x0180 0x018f
gpr0 0x0020 0x006f
gpr1 0x00a0 0x00ef
gpr2 0x0120 0x014f
testreg 0x01ff 0x01ff
ACCESSBANKS:
Kod: Markera allt
;---------------------------------------------------------
GET_TEMP:
CALL OW_RESET ; Send Reset Pulse and read for Presence Detect Pulse
BTFSS PDBYTE,0 ; 1 = Presence Detect Detected
GOTO NOPDPULSE
MOVLW SKPROM
CALL DSTXBYTE ; Send Skip ROM Command (0xCC)
MOVLW 0x69
CALL DSTXBYTE ; Send Read Data Command (0x69)
MOVLW 0x0E
CALL DSTXBYTE ; Send the DS2761 Current Register MSB address (0x0E)
CALL DSRXBYTE ; Read the DS2761 Current Register MSB
MOVF IOBYTE,W
MOVWF PICMSB ; Put the Current MSB into file PICMSB
CALL DSRXBYTE ; Read the DS2761 Current Register LSB
MOVF IOBYTE,W
MOVWF PICLSB ; Put the Current LSB into file PICLSB
CALL OW_RESET
NOPDPULSE: ; Add some error processing here!
SLEEP ; Put PIC to sleep
;---------------------------------------------------------
end