[TI-H] Re: PIC16F84 Interfacing


[Prev][Next][Index][Thread]

[TI-H] Re: PIC16F84 Interfacing




SendByte and RecvByte both work with file adc.
here is the code: (see below for hw)

-----------------------------------------------------------------------------------------------------------------------
include "p16f84.inc"
	 __CONFIG _CP_OFF & _HS_OSC & _PWRTE_ON  & _WDT_OFF


count1	EQU	0Ch
count2	EQU	0Dh
count3	EQU	0Eh
adc	EQU	0Fh
temp	EQU	10h
temp1	EQU	11h

WHITE 	EQU	0
RED	EQU	1

; RA0 wite TI-92+
; RA1 red TI-92+

	org	0	  ; start at address 0
	
init:
	bsf	STATUS,RP0	; mem page 1

	movlw	B'00000000'
	movwf	TRISA		; init port A as output
	bsf	TRISA, WHITE	; RA0 & RA1 entrada
	bsf	TRISA, RED

	movlw	0FFh
	movwf	TRISB		; port B input

	bcf	STATUS,RP0	; mem page 0

	clrf	PORTA	; salida PORTA en blanco
	clrf	PORTB	; salida PORTB en blanco (no afecta bits de entrada)

WaitForCommand:
	call	RecvByte		; wait for a command
	movlw	0FAh
	subwf	adc,W

	btfss	STATUS, Z		; is it FAh => request temp
	call	Send51Byte
	goto	WaitForCommand

Send51Byte:
	movlw	.52
	movwf	adc
	call	SendByte
	return


; ----------------------- ROUTINES --------------------------------

; ---- SENDBYTE STARTS -------------
SendByte:
	movlw	.9 ; a byte is made of 8 bits
	movwf	temp
Ver:
	decfsz	temp,F
	goto	CheckBits
	return		; return from SendByte

CheckBits:
	btfsc	adc,0
	goto	is1
	goto	is0

is1:
	bcf	PORTA,WHITE
	call	RedIn

	call	WaitRed0
	bsf	PORTA, WHITE
	call	WaitRed1
	rrf	adc

	call	BothIn
	call	WaitWhite1

	goto Ver
is0:
	bcf	PORTA, RED
	call	WhiteIn

	call	WaitWhite0
	bsf	PORTA, RED
	call	WaitWhite1
	rrf	adc

	call	BothIn
	call	WaitRed1
	goto Ver
; ------------ SEND BYTE ENDS --------------

; ----------- RECV BYTE STARTS --------------

RecvByte:
	movlw	.9 ; a byte is made of 8 bits
	movwf	temp

DecrementarR:
	decfsz	temp,F
	goto	RecibirBit
	return		; return from SendByte

RecibirBit:
	call	BothIn	; both inputs
	call	WaitRed1		; wait for white and red (wait!)
	call	WaitWhite1

	btfsc	PORTA, RED
	goto	isR1
	goto	isR0

isR1:
	bcf	PORTA, RED
	call	WhiteIn

	call	WaitWhite1
	bsf	PORTA, RED

	bsf	adc, 7
	rrf	adc

	goto	DecrementarR

isR0:
	bcf	PORTA, WHITE
	call	RedIn

	call	WaitRed1
	bsf	PORTA, WHITE

	bcf	adc, 7
	rrf	adc

	goto	DecrementarR

; ----------- RECV BYTE ENDS --------------
BothIn:
	bsf	STATUS,RP0	; mem page 1

	movfw	TRISA
	movwf	temp1

	bsf	temp1, WHITE
	bsf	temp1, RED

	movfw	temp1
	movwf	TRISA

	bcf	STATUS, RP0	; mem page 0

	return
RedIn:
	bsf	STATUS,RP0	; mem page 1

	movfw	TRISA
	movwf	temp1

	bcf	temp1, WHITE
	bsf	temp1, RED

	movfw	temp1

	movwf	TRISA

	bcf	STATUS, RP0	; mem page 0
	return
WhiteIn:
	bsf	STATUS,RP0	; mem page 1

	movfw	TRISA
	movwf	temp1

	bsf	temp1, WHITE
	bcf	temp1, RED

	movfw	temp1
	movwf	TRISA

	bcf	STATUS, RP0	; mem page 0
	return

WaitRed0:
	btfsc	PORTA, RED
	goto WaitRed0
	return
WaitRed1:
	btfss	PORTA, RED
	goto WaitRed1
	return
WaitWhite0:
	btfsc	PORTA, WHITE
	goto WaitWhite0
	return
WaitWhite1:
	btfss	PORTA, WHITE
	goto WaitWhite1
	return
-----------------------------------------------------------------------------------------------------------------------

the hardware is just the white wire connected to the RA0 port with a 3.9K 
resitance, and the red wire is the same but to RA1.
Ground from the link port goes to ground of the circuit with a 1k resistor.

Oh, it runs at 10mhz, but i think it works well at 4mhz.
Here is the program in tigcc..

void _main(void)
{
	unsigned char buffer;	
	ClrScr();
	while(ngetchx() != '+')
	{
		ClrScr();
		buffer = 0xFA;
		LIO_SendData (&buffer, sizeof(buffer));	// request for data

		LIO_RecvData (&buffer, sizeof(buffer), 40); // max of 2 seconds to wait 
and recv data
		printf_xy(10, 10, "Read: %u", buffer);
	}
}

thnxs.. oh.. as i said.. it works with VTI but not with the real ti-92+




Follow-Ups: References: