Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/31/07 18:15
Read: times


 
Msg Score: +1
 +1 Good Answer/Helpful
#131821 - Full code for reference if anyone's interested
Responding to: ???'s previous message
Please excuse any typos in the comments - it's been a long day.


;
;		Starting with ATMEL 89C51ED2 and SPI
;
;		LED on port 22 on wait 1 second
;		LED on port 23 on wait one second
;		LED on port 22 off wait one second
;		LED on port 23 off wait one second
;		Oh, the excitement!
;

$NOMOD
$TITLE(BYTE SPI_TEST)
$DEBUG
$OBJECT
$NOPAGING

;Variable declarations

$include(C:\asm51\89C51ED2.inc)

SS	EQU	P2.1 ;J7-29
	rec_data 			Data 	30h
	T1COUNT				Data	31h		;Timer 1 count
	trans_completed 	Bit 	00h
	ALARM1 				Bit 	01h  	;Flag for timer 1 set in timer 1 interrupt


;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
;			Macros
		
	START_50MS_TIMER MACRO FIFTY_MS_INTERVALS 	;FIFTY_MS_INTERVALS is the 
											;number of .05 second
											;intervals to wait for
		clr ET1
		clr alarm1
		orl TMOD,#10h       ;Set timer 1 to 16-bit mode
      	MOV TH1,#0B0H       
      	MOV TL1,#03CH ;Initialize TL1 to overflow every .05 seconds
      	SETB ET1            ;Enable timer interrupt 1
      	SETB EA             ;Enable all interrupts
      
      	MOV T1COUNT, FIFTY_MS_INTERVALS  ;Set T1COUNT to 20 to wait for 1s
      	SETB TR1        ;Turn timer 0 on								

ENDM
;
;			End of Macros
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++




org 0000H
	
	ljmp MAIN

ORG 001Bh
	
	ljmp T1_INTERRUPT	;Timer 1 interrupt 

org 4Bh
	
	ljmp SPI_INT

org 100h

MAIN:
	orl spcon, #10h
	setb SS
	orl spcon, #82h
	anl spcon, #0F7h ;cpol = 0
	mov a, spcon
	clr acc.2
	mov spcon, a
	orl ien1, #04h
	orl spcon, #40h
	clr trans_completed
	setb ea
	
	

;//////////////////////////////////////////////////////////////////////////////
;
;  Set up MAX6957 registers
;

	
	clr SS
	
	mov SPDAT,#04h				; config register
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#01h				; disable shutdown, global current control, trans det disabled
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
   	
   	setb SS						; read 2 bytes into SPI slave
	nop						; min CS pulse is 19 ns so at 12 MHz one nop should do it
	
	clr SS
	
	mov SPDAT,#0Dh				; ports 20, 21, 22, 23 config register
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#0Ch				; set port 22 & 23 to LED Driver
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
   	
   	   	
   	setb SS						; read 2 bytes into SPI slave
	nop					; min CS pulse is 19 ns so at 12 MHz one nop should do it

   	
;//////////////////////////////////////////////////////////////////////////////
;
;  Main loop
;   	
LOOP1:
   	clr SS
   	mov SPDAT,#36h				; port 22
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#01h				; on
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */

   	setb SS	
	nop						; min CS pulse is 19 ns so at 12 MHz one nop should do it
	
	START_50MS_TIMER #20 ;Delay for 20 * .05 seconds
    jnb Alarm1, $ 

	clr SS
	
	mov SPDAT,#37h				; port 22
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#01h				; on
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */

   	setb SS	
	
	nop						; min CS pulse is 19 ns so at 12 MHz one nop should do it
	
	START_50MS_TIMER #20 ;Delay for 20 * .05 seconds
    jnb Alarm1, $ 

	clr SS
	
	mov SPDAT,#36h				; port 22
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#00h				; off
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
   	
   	   	
   	setb SS	
   	nop						; min CS pulse is 19 ns so at 12 MHz one nop should do it
	
	START_50MS_TIMER #20 ;Delay for 20 * .05 seconds
    jnb Alarm1, $ 

	clr SS
	
	mov SPDAT,#37h				; port 23
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */
	
   	mov SPDAT,#00h				; off
   	jnb trans_completed,$		; /* wait end of transmission */
   	clr trans_completed			; /* clear software transfer flag */

   	setb SS	
   	
   	START_50MS_TIMER #20 ;Delay for 20 * .05 seconds
    jnb Alarm1, $ 

	jmp  loop1						; endless loop
	
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
;
;			Timer1 interrupt. Timer 1 used for multiples of .05 seconds.	
		
	
T1_INTERRUPT: 
		MOV TH1,#03CH 
		MOV TL1,#0B0H 
		DJNZ T1COUNT,T1_EXIT ;If we haven't reached 0 then jump out of int routine 
		SETB ALARM1
		CLR ET1			  ;stop timer
      	CLR TR1

T1_EXIT: 
RETI 
;
;			End of Timer1 interrupt
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
;
;			SPI interrupt. 	
			
SPI_INT:						;  /* interrupt address is 0x004B */
	
	mov R7,SPSTA
	mov ACC,R7
	jnb ACC.7,BREAK1 			;case 0x80:
	mov rec_data,SPDAT 			;  /* read receive data */
    setb trans_completed 		;  /* set software flag */
BREAK1:

	jnb ACC.4,BREAK2 			;case 0x10:
	cpl p2.0 ;J7-31					; Debugging
		;  /* put here for mode fault tasking */	
BREAK2:
	
	jnb ACC.6,BREAK3 			;case 0x40:
	cpl p2.0 ;J7-31					; Debugging
								;  /* put here for overrun tasking */	
BREAK3:

RETI
;
;			End of SPI interrupt
;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

	
END



List of 48 messages in thread
TopicAuthorDate
Interfacing AT89C51ED2 to MAX6957 via SPI            01/01/70 00:00      
   a quick look            01/01/70 00:00      
      A bit hidden I know...            01/01/70 00:00      
   just a hint...            01/01/70 00:00      
      Thanks Jan            01/01/70 00:00      
      I know this is an Atmel chip, but            01/01/70 00:00      
         not that type of error            01/01/70 00:00      
   Light at the end of the tunnel...            01/01/70 00:00      
      Some scope traces...            01/01/70 00:00      
         CPOL = 0, CPHA = 0            01/01/70 00:00      
            Excellent.            01/01/70 00:00      
               What is the current problem?            01/01/70 00:00      
                  Thanks            01/01/70 00:00      
                     Next time...            01/01/70 00:00      
                        smiling            01/01/70 00:00      
                     this is what I was about to ask...            01/01/70 00:00      
                        a simple SPI 'test'            01/01/70 00:00      
                        MISO            01/01/70 00:00      
                           have you tried            01/01/70 00:00      
                              Good plan            01/01/70 00:00      
                                 Eureka            01/01/70 00:00      
                                    That's good...            01/01/70 00:00      
                                       true SPI and non-SPI driven by SPI            01/01/70 00:00      
                                          TRUE SPI chip?            01/01/70 00:00      
                                             OK            01/01/70 00:00      
                                    good choice            01/01/70 00:00      
                                       I used such...            01/01/70 00:00      
                                    Full code for reference if anyone's interested            01/01/70 00:00      
                           where did you measure?            01/01/70 00:00      
                           soldering iron...            01/01/70 00:00      
                              proto and prod            01/01/70 00:00      
                                 ah so...            01/01/70 00:00      
                                    HUH            01/01/70 00:00      
                                       now I really don\'t understand            01/01/70 00:00      
                                          well, let me try again            01/01/70 00:00      
                                             Oh I see...            01/01/70 00:00      
                                                try asking the person that does my layouts            01/01/70 00:00      
                                                Layout tool?            01/01/70 00:00      
                                                   tool... yes maybe, but for X1/X2???            01/01/70 00:00      
                                                      Just curious...            01/01/70 00:00      
                                                         huh...            01/01/70 00:00      
                                                   DXP            01/01/70 00:00      
                                                      Let's move to chat? (off-topic)            01/01/70 00:00      
                        The problem lies on MAX6957            01/01/70 00:00      
   I am happy for you            01/01/70 00:00      
      Thanks Erik            01/01/70 00:00      
      waitaminute...            01/01/70 00:00      
         comments            01/01/70 00:00      

Back to Subject List