|
Yeah, Now thats fucken NEWSSS!!!
(this is irrelevant but I must attach here. It might explain why I've been away for a while )
;*************************************************************************
; Filename: I2CTEA.ASM
; Author : Tranceilvania
; Purpose : MCU code TEA6415
; Osc Freq: 4 MHz
;
;*************************************************************************
;**************** Assembler Setup ****************************************
LIST P=16F84A, F=INHX8M, C=100, N=59
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_OFF & _RC_OSC
#include "p16f84a.inc" ; processor specific variables
;*************************Equates****************************************
dev_address equ b'10000110' ; TEA6415 specific device write address
output_Q3 equ b'00000000' ; output, data frame for pin18 of TEA6415(pin 1 of socket J1)
input_Soc2 equ b'00000110' ; input, data frame for pin20 of TEA6415(pin 2 of socket J4)
MSB equ 0x07 ; position of most significant bit. transmitted first
LSB equ 0x00 ; least sig bit goes last in the pulse train
COUNT equ 0x0C ; Number of bits to send
tx_reg equ 0x11 ; Transmit buffer
ACKSTATUS equ 0x16 ; Acknowledment status register. either ACK=0 NACK=1
HIGHBYTE equ 0x14 ;
;*************************DEFINITIONS************************************
;define pseudo instructions
#define SDA PORTA, 0 ; Pin for SDA RA0 pin17
#define SCL PORTA, 1 ; Pin for SCL RA1 pin18
#define BANK1 BSF STATUS, RP0 ;
#define BANK0 BCF STATUS, RP0 ;
;define bits
#define all_ones b'11111111' ;setting all porta to inputs
#define all_zeros b'00011100' ;setting SDA & SCL outputs. leaving buttons as inputs
;**************************POWER ON RESET********************************
org 0x00 ; Reset Vector
goto start ; Goto Start
;**********************START OF CODE*************************************
org 0x10 ;start location
start ; -put ports
BANK0 ;select Page 0 of registers
bcf INTCON, GIE ;Turn off Interrupts
movlw all_ones ; 1's on SCL and SDA
movwf PORTA ; 1's to TX
BANK1 ; Page 1 of registers
movlw all_zeros ; W with the value for TRIS A
movwf TRISA ; the value from W into TRIS A
BANK0
main
movlw dev_address ; address of slave i2c device
movwf SlaveAddr ; SlaveAddress register
;buttons
;btfsc PORTA,2 ;
;CALL 'subroutine-1'
;btfsc PORTA,3 ; rst ;CALL 'subroutine-2'
Send_Address
CALL STARTFR ;send start signal
;send address byte sequence follows
MOVLW dev_address ;address byte read operation
MOVWF tx_reg
CALL SENDBYTE ;transmit the byte
BCF ACKSTATUS,1 ; ACK Req'd for first byte
GOTO MAIN
END
;**************Data Table***************************
;----outputs------------
;Q3(pin18) output 00000-
;Q2(pin17) output 00001-
;Q1(pin16) output 00010-
;R pin15 output 00011-
;G pin14 output 00100-
;B pin13 output 00101-
;----inputs-------------
;1 Soc2(pin20) input -110
;2 Soc3(pin01) input -011
;3 Soc4(pin03) input -010
;4 Soc5(pin05) input -000
;5 Soc6(pin06) input -001
;6 Soc7(pin08) input -100
;7 Soc8(pin10) input -101
;8 Soc9(pin11) input -111
;***********************************************************

|