;==================
; PROGRAMA PARA LER INFORMAÇOES CONTIDAS NO 
; IBUTTON DS1990A
; E APRESENTAR OS DADOS EM UM DISPLAY
;==================
;==========================================================================
;      bits de configuração de fusivel
;==========================================================================

;_cp_on                       equ     h'3fef'
;_cp_off                      equ     h'3fff'
;_pwrte_on                    equ     h'3fff'
;_pwrte_off                   equ     h'3ff7'
;_wdt_on                      equ     h'3fff'
;_wdt_off                     equ     h'3ffb'
;_lp_osc                      equ     h'3ffc'
;_xt_osc                      equ     h'3ffd'
;_hs_osc                      equ     h'3ffe'
;_rc_osc                      equ     h'3fff'



	list 	p=16f84
	include	p16f84.inc
	__config _wdt_off & _xt_osc & _pwrte_off & _cp_off

;============================================
; para ajuste do display
;=====================================

DISP_RST	EQU	0X003		; Display RESET
DISP_ON_C 	equ 	0x00E 		; display ON, cursor ON, blink OFF
DISP_ON 	equ 	0x00C 		; display ON, cursor OFF, blink OFF
DISP_ON_CB 	equ 	0x00F 		; display ON, cursor ON, blink ON
DISP_ON_B 	equ 	0x00D 		; display ON, cursor OFF, blink ON
DISP_OFF 	equ 	0x008 		; display OFF
CLR_DISP 	equ 	0x001 		; clear display
HOME_DISP 	equ 	0x002 		; home display
SHR_C 		equ 	0x01C 		; shift right 1 char
SHL_C 		equ 	0x018 		; shift left 1 char
ENTRY_INC 	equ 	0x006 		; entry mode increment, no shift
ENTRY_INC_S 	equ 	0x007 		; entry mode increment, shift
ENTRY_DEC 	equ 	0x004 		; entry mode decrement
ENTRY_DEC_S 	equ 	0x005 		; entry mode decrement, shift
DD_RAM_ADDR 	equ 	0x080 		; least significant 7 bits are for address
DD_RAM_UL 	equ 	0x080 		; upper left corner of display
DD_RAM_half	equ	0x0c0		;segunda parte do display

LCD_DATA         EQU     PORTB
LCD_CNTL         EQU     PORTA
CHAR		EQU	0x036			; Temporary register, Holds value to send to LCD module.

TEMP1       EQU     0x030
Dlay        EQU     0x031               ;  8 Bit Delay Variable
;======================================================================

cblock	0x0c
	ls_digit
	ms_digit	;ascii, nibble superior
	hold
	familia
	dado_1
	dado_2
	dado_3
	dado_4
	dado_5
	dado_6
	crc
	crc1
	temp
	crc_temp
	familia_a
	dado_1_a
	dado_2_a
	dado_3_a
	dado_4_a
	dado_5_a
	dado_6_a
	crc_a
	bits		
	contador
	contador1
	BIT
	mcount
	ncount
	ocount
	sendreg
endc

;-------------------------
;bits em uso
;-------------------------
entrada		equ	1	;bit de entrada
saida		equ	0	;bit de saída
verde		equ	0	;led verde
vermelho	equ	1	;led vermelho
crc_ok		equ	3	;1 indica crc=ok
bit_lido	equ	7	;valor do bit lido na porta de entrada
CRC_CONFERE	EQU	1	;INDICA SE O VALOR DO CRC ESTÁ CORRETO = 1
E		EQU	2	;DISPLAY ENABLE
RS		EQU	3	;DISPLAY controle DATA/INSTRUCTIONS

;=================================
;hardware:
;
;RB0 - LED VERDE (CATODO) LIGAR ANODO COM R=1K AO VCC
;RB1 - LED VERMELHO (CATODO) LIGAR ANODO COM R=1K AO VCC
;
;RB4 - BIT4 (LCD)
;RB5 - BIT5 (LCD)
;RB6 - BIT6 (LCD)
;RB7 - BIT7 (LCD)

;

;RA0 - BIT DE SAIDA
;RA1 - BIT DE ENTRADA
;RA2 - E  (LCD)
;RA3 - RS (LCD)

;                      5K6 PULL-UP
;               +(5V)-/\/\/--I
; RA1 -----------------------+------> IBUTTON
;                            I
;        2K2           B   I/  C
; RA0 --\/\/\/-------------I
;                          I\  E (BC517)
;                            I
;                           GND

;=================================


	org	0

	bsf	status,rp0	;vai para o banco 1
        MOVLW   0x00            ; 0x00 The LCD module does not like to work w/ weak pull-ups
	MOVWF	OPTION_REG      ;
	movlw	b'00010010'	;bit 0 entrada
	movwf	trisa
	movlw	0x00	
	movwf	trisb		;porta B só de saída
        BSF     OPTION_REG,NOT_RBPU  ; Disable PORTB pull-ups
	bcf	status, rp0	;volta ao banco 0
	clrf	porta
	clrf	portb
;==================
	call	aguarda
	CALL	disp_init
	call	display
	call	aguarda
	call	carga_chave
	clrf	familia
	clrf	crc
	clrf	dado_1
	clrf	dado_2
	clrf	dado_3
	clrf	dado_4
	clrf	dado_5
	clrf	dado_6
;=================


inicio	
	call	reset		;carry=0 ausente / carry= 1 presente
				;bits(0)=1 curto / bits(0)=0 OK
	btfsc	bits, 0		;se ok, tem ibutton
	goto	curto
	btfss	status, c	;testa se presente
	goto	ausente
	call	comando_le_ROM
	call	le_ROM
	call	mostra_dados
				;testa se crc = 0
	btfss	bits, crc_ok	;se nao houver erros, continua...
	goto	erro
	call	confere_serial
	btfss	bits, 1		;bits(1)=1 confere
	goto	nao_confere	;byte confere?
	bcf	portb, verde	;acende led verde
	bsf	portb, vermelho	;apaga led vermelho

	goto	inicio
;--------
; rotinas para apresentacao de dados
;----------

ausente			
	call	del_5

	movlw	DD_RAM_addr	;posiciona no canto esquerdo
	call	send_cmd
	movlw	'i'		;escreve ibutton ausente
	call	send_char
	movlw	'B'
	call	send_char
	movlw	'u'
	call	send_char
	movlw	't'
	call	send_char
	movlw	't'
	call	send_char
	movlw	'o'
	call	send_char
	movlw	'n'
	call	send_char
	movlw	' '
	call	send_char
	movlw	' '
	call	send_char
	movlw	'A'
	call	send_char
	movlw	'U'
	call	send_char
	movlw	'S'
	call	send_char
	movlw	'E'
	call	send_char
	movlw	'N'
	call	send_char
	movlw	'T'
	call	send_char
	movlw	'E'
	call	send_char
				;muda de linha
				;escreve identidade
	CALL	AGUARDA
	goto	inicio

;---------
erro			;verde-apagado  vermelho-pisca
	movlw	DD_RAM_addr	;posiciona no canto esquerdo
	call	send_cmd
	movlw	'i'		;escreve ibutton ausente
	call	send_char
	movlw	'B'
	call	send_char
	movlw	'u'
	call	send_char
	movlw	't'
	call	send_char
	movlw	't'
	call	send_char
	movlw	'o'
	call	send_char
	movlw	'n'
	call	send_char
	movlw	' '
	call	send_char
	movlw	'c'
	call	send_char
	movlw	'/'
	call	send_char
	movlw	' '
	call	send_char
	movlw	'E'
	call	send_char
	movlw	'R'
	call	send_char
	movlw	'R'
	call	send_char
	movlw	'O'
	call	send_char
	movlw	' '
	call	send_char

	call	aguarda
	call	aguarda
	call	aguarda
	call	aguarda
	goto	inicio

;------
curto		
	movlw	clr_disp	;limpa display
	call	send_cmd
	call	del_5

	movlw	DD_RAM_addr	;posiciona no canto esquerdo
	call	send_cmd
	movlw	' '		;escreve ibutton ausente
	call	send_char
	movlw	' '
	call	send_char
	movlw	'E'
	call	send_char
	movlw	'M'
	call	send_char
	movlw	' '
	call	send_char
	movlw	' '
	call	send_char
	movlw	'C'
	call	send_char
	movlw	'U'
	call	send_char
	movlw	'R'
	call	send_char
	movlw	'T'
	call	send_char
	movlw	'O'
	call	send_char
	movlw	' '

	CALL	AGUARDA
	goto	inicio

;----
nao_confere		;verde-apagado   vermelho-aceso
	movlw	DD_RAM_addr	;posiciona no canto esquerdo
	call	send_cmd
	movlw	'i'		;escreve ibutton N CONFERE
	call	send_char
	movlw	'B'
	call	send_char
	movlw	'u'
	call	send_char
	movlw	't'
	call	send_char
	movlw	't'
	call	send_char
	movlw	'o'
	call	send_char
	movlw	'n'
	call	send_char
	movlw	' '
	call	send_char
	movlw	'N'
	call	send_char
	movlw	' '
	call	send_char
	movlw	'C'
	call	send_char
	movlw	'O'
	call	send_char
	movlw	'N'
	call	send_char
	movlw	'F'
	call	send_char
	movlw	'E'
	call	send_char
	movlw	'R'
	call	send_char
	movlw	'E'
	call	send_char

	CALL	AGUARDA
	call	aguarda
	goto	inicio


;=============================
; ROTINA DE RESET DO IBUTTON
;============================

reset		; reset e pulso de presença
	bcf	bits, 0
	bsf	porta, saida		;porta em 0
	movlw	167
	movwf	contador
				;aguarda 500us em nivel baixo
	decfsz	contador	
	goto	$-1		
	bcf	porta, saida	;porta em 1
	movlw	10
	movwf	contador	;aguarda 30us para recweber pulso
	decfsz	contador
	goto	$-1

	movlw	83		;testa se há pulso por 240us
	movwf	contador

teste_pulso
	btfss	porta, entrada	;testa se a porta está em zero 
	goto	Pulso_presente	; (presence Pulse)
	decfsz	contador
	goto	teste_pulso
	goto 	ibutton_ausente	;indica que houve overflow, sem resposta.

pulso_presente
	decf	contador	;verifica se o pulso é estável
	btfsc	3,2
	goto	ibutton_ausente
	decf	contador
	btfsc	3,2		;overflow, sai da rotina
	goto	ibutton_ausente
	decf	contador
	btfsc	3,2
	goto	ibutton_ausente
	btfsc	porta, entrada
	goto	teste_pulso	;continua testando 


;===================
;se chegou aqui o pulso é valido
; espere o tempo total de recuperacao
;e retorne com o CARRY setado para indicar 
;que existe ibutton
;===================	
	decfsz	contador
	goto	$-1
	movlw	83
	movwf	contador
	decfsz	contador
	goto	$-1
	bcf	bits, 0
	btfss	porta, entrada	;testa se porta esta em curto
	goto	curto_entrada
	bsf	status, C
	return

curto_entrada
	bsf	bits, 0	;indica curto-circuito na entrada
	bcf	status, c
	return

ibutton_ausente
	movlw	83		;aguarda 240us 
	movwf	contador	;para termino do ciclo
	decfsz	contador
	goto	$-1
	bcf	status, C	;reseta o carry indicando que nao
	return			;há ibutton

;================================
; ESCRITA DE DE BIT UM
;================================

escrever_um
	bsf	porta, saida	;saida em zero
	nop
	nop
	nop
	bcf	porta, saida	;tlow = 3us
	movlw	20
	movwf	contador
 	decfsz	contador, f	;tslot = 7 + 3*19 + 2 + 2= 68
  	goto	$-1
	return
;=========================
; ESCRITA DE BIT ZERO
;========================

escrever_zero
	bsf	porta, saida
	movlw	22		;Tlow = 68 us
	movwf	contador
	decfsz	contador,f
	goto	$-1
	bcf	porta, saida
	return


;========================
;leitura do bit de entrada
;o bit é gravado no MSB do registrador "bits"
;bits(7)= 0 ou bits(7)= 1 "bit_lido"
;========================

leitura
	bsf	porta, saida	;pulso de sincronismo
	nop
	nop
	bcf	porta, saida
	nop
	nop
	nop
	nop
	nop
	nop
	bcf	bits, bit_lido		;janela de leitura,
	btfsc	porta, entrada		;armazena bit lido em bits(7)
	bsf	bits, bit_lido

	movlw	20
	movwf	contador
	decfsz	contador
	goto 	$-1
	
	return
	
;=========================
;ESCREVE O COMANDO DE LEITURA DE ROM 33H
;8 BITS
;=========================

comando_le_ROM
			;escreve 0x33 na porta de saida
	movlw	0x33
	movwf	sendreg
	movlw	8
	movwf	temp
repete
	rrf	sendreg, 1
	btfsc	status, c	;bit0	;se carry = 1 escreve 1
	goto	bit_um
	call	escrever_zero
	goto	teste_byte
bit_um
	call	escrever_um
teste_byte
	decfsz	temp
	goto	repete
	return

;============================
;LÊ O VALOR ENCONTRADO NA ROM DO IBUTTON
;
;--------------
; ESTRUTURA DOS DADOS:
; CRC -  UNIQUE SERIAL NUMBER   - FAMILY CODE
; 1B    1B  1B  1B  1B  1B  1B     1B
;--------------
;
;============================
le_ROM
;	familia
;	dado_1
;	dado_2
;	dado_3
;	dado_4
;	dado_5
;	dado_6
;	crc
;	crc1
;	crc_temp	
;	contador1
	clrf	crc1
	clrf	crc_temp

le_dados
	movlw	64
	movwf	contador1
retorno_leitura
	call	leitura
	rlf	bits,0		;transfere bit lido para Carry, sem alterar
				;registrador "bits"
	rrf	crc, 1		;rotaciona dado atraves do carry
	rrf	dado_6, 1
	rrf	dado_5, 1
	rrf	dado_4, 1
	rrf	dado_3, 1
	rrf	dado_2, 1
	rrf	dado_1, 1
	rrf	familia, 1
	call	atualiza_crc
	decfsz	contador1
	goto	retorno_leitura
testa_crc
	bcf	bits, crc_ok	;crc invalido
	movf	crc1,1
	btfsc	status, z	;testa se crc =0
	bsf	bits, crc_ok	;e indica que é valido
	return


;=====================================================
mostra_dados
;	familia
;	dado_1
;	dado_2
;	dado_3
;	dado_4
;	dado_5
;	dado_6
;	crc

	movlw	clr_disp	;limpa display
	call	send_cmd
	call	del_5

	movlw	DD_RAM_addr	;posiciona no canto esquerdo
	call	send_cmd
		
	movlw	' '
	call	send_char

	movlw	'V'
	call	send_char

	movlw	'a'
	call	send_char

	movlw	'l'
	call	send_char

	movlw	'o'
	call	send_char

	movlw	'r'
	call	send_char

	movlw	' '
	call	send_char

	movlw	'L'
	call	send_char

	movlw	'i'
	call	send_char

	movlw	'd'
	call	send_char

	movlw	'o'
	call	send_char


	movlw	DD_RAM_half
	call	send_cmd

	movf	familia, 0
	call	sephex

	movf	dado_6, 0
	call	sephex


	movf	dado_5, 0
	call	sephex


	movf	dado_4, 0
	call	sephex

	

	movf	dado_3, 0
	call	sephex


	movf	dado_2, 0
	call	sephex


	movf	dado_1, 0
	call	sephex

	MOVf	CRC, 0
	CALL	SEPHEX
	call	aguarda

	return



;=====================================
atualiza_crc
	rlf	bits, 0		;copia bit em crc_temp
	rlf	crc_temp, 1
	movf	crc1, 0
	xorwf	crc_temp, 1	;salva resultado em crc_temp
	rrf	crc_temp, 1	;coloca bit em carry
	movf	crc1, 0		;coloca crc em temporario,
	movwf	crc_temp	; passando por W
	btfss	status, c
	goto	zero
um	movlw	0x18		;faz xor com os bits 4 e 5
	xorwf	crc_temp, 1	; e salva resultado em temporario
zero
	rrf	crc_temp, 1	;pega primeiro bit e soma com carry
	movf	crc_temp, 0	;restaura crc
	movwf	crc1
	return	

;===========================
;TESTA O VALOR DOS BITS LIDOS
;
; SE O valor confere => bits(1) =1
;CRC_CONFERE = 1
;===================
confere_serial
	bcf	bits, CRC_CONFERE
	movf	familia, 0
	subwf	familia_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_1, 0
	subwf	dado_1_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_2, 0
	subwf	dado_2_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_3, 0
	subwf	dado_3_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_4, 0
	subwf	dado_4_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_5, 0
	subwf	dado_5_a, 0
	btfss	status, z
	goto	sai_confere
	movf	dado_6, 0
	subwf	dado_6_a, 0
	btfss	status, z
	goto	sai_confere
	bsf	bits, CRC_CONFERE		;dados conferem
	return
sai_confere
	return
;=================
aguarda
	movlw	2
	movwf	ocount
loadm	movlw	0xff
	movwf	mcount	;m
loadn	movlw	0xff
	movwf	ncount	;n
decn	decfsz	ncount, f
	goto	decn
	decfsz	mcount, f
	goto	loadn
	decfsz	ocount, f
	goto	loadm
	return
;=================
carga_chave

;familia_a	equ	0x01
;dado_1_a	equ	0xc9
;dado_2_a	equ	0xb9
;dado_3_a	equ	0x07
;dado_4_a	equ	0x06
;dado_5_a	equ	0x00
;dado_6_a	equ	0x00
;crc_a		equ	0xdf

;	movlw	clr_disp	;limpa display
;	call	send_cmd
	call	del_5

	movlw	DD_RAM_half
	call	send_cmd

	movlw	0x01
	movwf	familia_a
	call	sephex

	movlw	0x00
	movwf	dado_6_A
	call	sephex

	movlw	0x00
	movwf	dado_5_a
	call	sephex

	movlw	0x06
	movwf	dado_4_a
	call	sephex

	movlw	0x07
	movwf	dado_3_a
	call	sephex

	movlw	0xb9
	movwf	dado_2_a
	call	sephex

	movlw	0xc9
	movwf	dado_1_a
	call	sephex

	movlw	0xdf
	movwf	crc_a
	call	sephex

	return

;==========================
;= inicializacao do LCD
;==========================
disp_init
	call   del_5                  ;  Wait 20 msecs before Reset
	call   del_5
	call   del_5
	call   del_5

	bcf    STATUS, C              ;  Clear Carry (Instruction Out)
	movlw  DISP_RST                   ;0x03  Reset Command
				; 0000 0011
	CALL	SEND_CMD


	call	 del_5			;  Wait 5 msecs before Sending Again

	movlw  DISP_RST			;0x03 
	CALL	SEND_CMD

	call	 del_125		;  Wait 160 usecs before Sending the Third Time

	movlw  DISP_RST			;0x03 
	CALL	SEND_CMD

	call	 del_125		;  Wait 160 usecs before Sending the Third Time

	movlw  0x02                   ; 0010 0000 Set 4 Bit Mode (function set)
				; 001L NF**
	CALL	SEND_CMD

	call	 del_125		

	movlw	 0x028			; 0010 1000 Note that it is a 2 Line Display
				; 0010 NF**
	CALL	SEND_CMD

	movlw	 DISP_OFF			; 0000 1000 Turn off the Display
				; 0000 1DCB
	CALL	SEND_CMD

	movlw	 CLR_DISP			; 0000 0001 Clear the Display RAM
	CALL	SEND_CMD
	call	 del_5			;  Note, Can take up to 4.1 msecs

	movlw	 ENTRY_INC			; 0000 0110 Enable Cursor Move Direction
				; 0000 01IS
	CALL	SEND_CMD

	movlw	 DISP_ON_B			; 0000 1111 Turn the LCD Back On
				; 0000 1DCB
	CALL	SEND_CMD

	call	 del_5			;  Note, Can take up to 4.1 msecs

            MOVLW   DD_RAM_ADDR     ;
            CALL    SEND_CMD        ;
	  call	Del_5

	return

;*******************************************************************
;* The LCD Module Subroutines                                      *
;*******************************************************************
;
;*******************************************************************
;*SendChar - Sends character to LCD                                *
;*This routine splits the character into the upper and lower       * 
;*nibbles and sends them to the LCD, upper nibble first.           *
;*******************************************************************
;
SEND_CHAR
            MOVWF   CHAR            ;Character to be sent is in W
            CALL    del_125		;  Wait 160 usecs
            MOVF    CHAR, w          
            ANDLW   0xF0            ;Get upper nibble
            MOVWF   LCD_DATA        ;Send data to LCD
            BSF     LCD_CNTL, RS    ;Set LCD to data mode
            BSF     LCD_CNTL, E     ;toggle E for LCD
            BCF     LCD_CNTL, E
            SWAPF   CHAR, w
            ANDLW   0xF0            ;Get lower nibble
            MOVWF   LCD_DATA        ;Send data to LCD
            BSF     LCD_CNTL, E     ;toggle E for LCD
            BCF     LCD_CNTL, E
            RETURN

;*******************************************************************
;* SendCmd - Sends command to LCD                                  *
;* This routine splits the command into the upper and lower        * 
;* nibbles and sends them to the LCD, upper nibble first.          *
;* The data is transmitted on the PORT<4:7> pins                   *
;*******************************************************************
;
;*******************************************************************
;* SEND_CMD - Sends command to LCD                                 *
;* This routine splits the command into the upper and lower        * 
;* nibbles and sends them to the LCD, upper nibble first.          *
;*******************************************************************

SEND_CMD
            MOVWF   CHAR            ; Character to be sent is in W
            CALL    del_125		;  Wait 160 usecs Wait for LCD to be ready
            MOVF    CHAR,w          
            ANDLW   0xF0            ; Get upper nibble
            MOVWF   LCD_DATA        ; Send data to LCD
            BCF     LCD_CNTL,RS     ; Set LCD to command mode
            BSF     LCD_CNTL,E      ; toggle E for LCD
            BCF     LCD_CNTL,E
            SWAPF   CHAR,w
            ANDLW   0xF0            ; Get lower nibble
            MOVWF   LCD_DATA        ; Send data to LCD
            BSF     LCD_CNTL,E      ; toggle E for LCD
            BCF     LCD_CNTL,E
            RETURN

;==============
;ROTINA PARA SEPARAR UM BYTE HEXA EM DOIS CARACTERES ASCII
;e enviar para o display
;==============
sephex
	movwf	temp
	andlw	0x0f	;mascara o nibble superior
	call	hex2asc	;rotina para converter em ascii
;	call	send_char	;envia menos significativo
	movwf	ls_digit
	swapf	temp, w
	andlw	0x0f
	call	hex2asc
	call	send_char	;envia mais significativo
	movwf	ms_digit
	movf	ls_digit, 0
	call	send_char

	return
;===================
; ROTINA PARA CONVERTER UM VALOR EM HEXA PARA ASCII
;==================
hex2asc
	movwf	hold		;armazena uma copia
	sublw	0x09		;subtraia w de 1 - ox0a
	btfss	status, c	;carry=1 se w < 0x0a
	goto	add37
	goto	add30
add37
	movf	hold, w
	addlw	0x37
	return
add30
	movf	hold, w
	addlw	0x30
	return

;===============
; rotina de retardo de 160 us
;==============

del_125                         ;  Delay 160 usecs

  movlw  0X0FF - 40		;1  Loop Until Carry Set   256-40
  addlw  1			;1
  btfss  STATUS, C		;1 na verdade sao 162 usecs
   goto  $-2			;2
				;1    1+(1+1+2)*40+1=162
  return


;=================
;retardo de 5ms
;=================
Del_5                           ;  Delay 5 msecs

  movlw  4                      ;1  Set up the Delay
  movwf  Dlay			;1
  movlw  0X0FF - 0x0E8		;1
  addlw  1			;1
  btfsc  STATUS, Z		;1	1+1+1+[(1+2+2)*238+1+2]*4+1+2=4778 usecs
   decfsz Dlay			;1
    goto $-3			;2   volta 3 posicoes

  return

;=====================
;Send a message the hard way
;=====================
display

            movlw   'L'
            call    SEND_CHAR
            movlw   'e'
            call    SEND_CHAR
            movlw   'i'
            call    SEND_CHAR
            movlw   't'
            call    SEND_CHAR
            movlw   'o'
            call    SEND_CHAR
            movlw   'r'
            call    SEND_CHAR
            movlw   ' '
            call    SEND_CHAR
            movlw   'd'
            call    SEND_CHAR
		movlw	0xc0
	    movlw   ' '
            call    SEND_CHAR
	    movlw   'i'
            call    SEND_CHAR
	    movlw   'B'
            call    SEND_CHAR
	    movlw   'u'
            call    SEND_CHAR
	    movlw   't'
            call    SEND_CHAR
	    movlw   't'
            call    SEND_CHAR
	    movlw   'o'
            call    SEND_CHAR
	    movlw   'n'
            call    SEND_CHAR




	movlw	DD_RAM_half
	call	send_cmd

 
            movlw   ' '
            call    SEND_CHAR
            movlw   'E'
            call    SEND_CHAR
            movlw   'd'
            call    SEND_CHAR
            movlw   'u'
            call    SEND_CHAR
            movlw   'a'
            call    SEND_CHAR
            movlw   'r'
            call    SEND_CHAR
            movlw   'd'
            call    SEND_CHAR
            movlw   'o'
            call    SEND_CHAR
	call	aguarda
	call	aguarda
	call	aguarda
	call	aguarda

return

;==================
teste
	clrf	temp
	bcf	status, z
	movlw	1
	movf	temp,0		;altera zero altera W
	bcf	status, z
	movlw	1
	movf	temp,1	
	;altera zero e nao altera W
	return

END
