Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

AVR C and Assembly Language Programming

Status
Not open for further replies.

mahesXtremeEngineering

Advanced Member level 4
Joined
Dec 17, 2011
Messages
103
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Activity points
1,832
I am working on a project using ATtiny2313. I got the source code in an .asm file. It says that it is written using AVR Studio. How can i use this this file and burn on the uC.
 
Last edited:

Re: Difference between C & Embedded C

I am working on a project using ATtiny2313. I got the source code in an .asm file. It says that it is written using AVR Studio. How to can use this this file and burn on the uC.

Do you have a AVR programmer, like an AVRisp, JTAGICE or a third party device?

You'll need to download AVR Studio, I recommend version 4. Create a project and assembly it within the AVR Studio and then program your ATtiny with the resulting HEX file using your ISP programmer.

The following are tutorials to help step you through the process:

Novice’s Guide to AVR Development

**broken link removed**



**broken link removed**

BigDog
 
Re: Difference between C & Embedded C

An ASM file is simply a text file with an ASM extension, so any text editor should be able to open it for viewing:

File: SMS_remote_control_ericsson_module.asm

Code:
;	
;	
;	SMS REMOTE CONTROL, WITH SONY-ERICSSON GSM MODULE GM47
;
;
;	written with AVR studio 4.12
; 
;
;	by Serasidis Vasilis 
;
;	Home: http://www.serasidis.gr
;	email: info@serasidis.gr - avrsite@yahoo.gr
;	
;	
;	Target: ATtiny2313 with 4 MHz crystal
;	PD0 = RxD
;	PD1 = TxD
;	PD2-PD5 = 4 RELAYS
;	PB0-PB7 = 8 INPUTS.
;	
;   Created at 04.Jan.2006 by Vassilis Serasidis
;   This source code is distributed under GNU public license (License file is included in the zip file).
;	If you don't agree with the license, please do not use this file.
;	
;	



.equ	BAUD		=25 	;9600 bps at 4.00 MHz.
.equ	RamStart	=96		;First RAM address byte.
.equ	SMSC		=100	;RAM address for SMS Service Center 
.equ	TPDA		=118	;RAM address for Sender's number 
.equ	TimeDate	=134	;RAM address for Time and date of received SMS
.equ	ASCII_HEX 	=185	;RAM address for ASCII to HEX conversion
.equ	SMScommand	=150	;RAM address for encoded SMS command (11001010)
.equ	Relay1		=2	
.equ	Relay2		=3
.equ	Relay3		=4
.equ	Relay4		=5
.equ	good		=$10
.equ	error		=$20

.def	eeadr	=R17
;.def	backup_status_register = r5
.def	temp	=R16		;temporary storage register
.def	Txbyte	=R18		;Data to be transmitted
.def	Rxbyte	=R19		;Received data
.def	temp2	=R20
.def	temp3	=R21
.def	temp4	=R22
.def	No_of_relay	=R22
.def	output	=R23
.def	Byte_counter	=R24
.def	No_Of_ignore_bytes		=R25		;
.def	status =r26

.def	delay1	=R26
.def	delay2	=R27
.def	YLramadr=R28
.def	YHramadr=R29
.def	delay3	=R29
.def	ZLramadr=R30
.def	ZHramadr=R31

.include "tn2313def.inc"		;Define chip particulars


;========================================================================


.org	0
	rjmp	reset

;.org	OVF0addr			; Timer/Counter0 Overflow
;	clr		interrupt
;	in 		backup_status_register,SREG
;	inc		interrupt
;
;	ldi		temp,0b11001100
;	out		portb,temp
;	out 	SREG,backup_status_register
;	reti


;*******************************************************************

;read_module_ID:			.db "ATI" ,0x0d, 0					;Show module's ID (GM47)
;enable_clip:			.db "AT+CLIP=1" ,0X0d, 0			;enable CLIP
select_phone_memory:	.db	"AT+CPMS=",'"',"ME",'"',0x0d,0	;Select the phone memory ("ME")
set_text_mode:			.db "AT+CMGF=1" ,0x0d,0,0			;Select text mode
;enable_RI_on_SMS:		.db "AT*E2SMSRI=1000" ,0x0d, 0		;Enable Ring pin after incomming SMS.
Hide_SMS_details:		.db "AT+CSDH=0", 0x0d,0,0			;Show only phone number, date-time, text of SMS.
Read_received_sms:		.db	"AT+CMGR=1" ,0x0d,0,0 			;read the received message(Memory possition 1)
Send_SMS_command:		.db "AT+CMGS=",0,0					;Send SMS command
Delete_SMS:				.db	"AT+CMGD=1" ,0x0d,0,0			;delete the received message (Memory possition 1)
Relay:					.db	"Relay", 0
cmdOut:					.db	"Input", 0								   	

.db "SMS REMOTE CONTROL, FOR SONY-ERICSSON GSM MODULE GM47 "
.db "Written by Serasidis Vasilis at December 2005 "
.db	"http://www.serasidis.gr info@serasidis.gr - avrsite@yahoo.gr"


.cseg
reset:

;	Setup buffers and pointers


	ldi		temp,RAMEND
	out		SPL,temp			;Init Stack Pointer


	ldi		temp,0b00000000
	out		DDRB,temp
	ldi		temp,0b11111111
	out		portB,temp

	ldi		temp,0b11111110
	out		DDRD,temp
	ldi		temp,0b00000000
	out		portD,temp

	;ldi	temp,(1<<CS02)+(0<<CS01)+(1<<CS00)
	;out	TCCR0,temp			; Set clock to count on CK/1024
	;ldi	temp,(1<<TOIE0)
	;out	TIMSK,temp			; enable timer 0 overflow interrupt

	ldi		temp,BAUD
	out		UBRR,temp			;Set baud rate generator


;===========   Set UART, as Transmiter   ======================

	ldi		temp,0b00011000
	out		UCR,temp			;Enable UART Tx and Rx 
;==============================================================


;==============================================================
;		Send command to module
;==============================================================
	
	rcall	long_delay

Start:
	;ldi		zl,low(read_module_ID*2)	;
	;ldi		zh,high(read_module_ID*2)	;
	;rcall	send_command
	;ldi		No_Of_ignore_bytes,1
	;rcall	receive2					;Read all response bytes.

	;ldi		zl,low(enable_clip*2)	;
	;ldi		zh,high(enable_clip*2)	;
	;rcall	send_command
	;rcall	receive

select_phone_mem:
	ldi		zl,low(select_phone_memory*2)	;
	ldi		zh,high(select_phone_memory*2)	;
	rcall	send_command
	rcall	receive2
	rcall	check_for_command_error
	cpi		temp,good
	brne	select_phone_mem

set_text_mod:
	ldi		zl,low(set_text_mode*2)		;
	ldi		zh,high(set_text_mode*2)	;
	rcall	send_command
	rcall	receive2
	rcall	check_for_command_error
	cpi		temp,good
	brne	set_text_mod

	;ldi		zl,low(enable_RI_on_SMS*2)		;
	;ldi		zh,high(enable_RI_on_SMS*2)	;
	;rcall	send_command
	;rcall	receive

Hide_SMS_detail:
	ldi		zl,low(Hide_SMS_details*2)		;
	ldi		zh,high(Hide_SMS_details*2)	;
	rcall	send_command
	rcall	receive2
	rcall	check_for_command_error
	cpi		temp,good
	brne	Hide_SMS_detail


	ldi		zl,low(Read_received_sms*2)		;
	ldi		zh,high(Read_received_sms*2)	;
	rcall	send_command
	rcall	receive2
	rcall	check_for_command_error
	cpi		temp,good
	brne	start


Read_receiv_sms:
	ldi		zl,low(Read_received_sms*2)		;
	ldi		zh,high(Read_received_sms*2)	;
	rcall	send_command

	ldi		No_Of_ignore_bytes,71	;ignore first 71 bytes of received SMS (part: +CMGR: "REC READ","+306947123456",,"05/11/29,14:17:12+08"[CR][LF] )
	rcall	from_read_phone_number	

	rcall	check_for_command_error
	cpi		temp,good
	brne	exit_from_here

;==============================================================
;
;==============================================================

;	ldi		txbyte,'a'
;	rcall	b_transmit
;	ldi		txbyte,'t'
;	rcall	b_transmit
;	ldi		YL,RamStart
;
;send_all_rambytes:
;	ld		txbyte,Y+
;	tst		txbyte		;test if txbyte is zero
;	breq	loop		;if yes, go to loop	
;	rcall	b_transmit
;	out		portb,txbyte
;	rjmp	send_all_rambytes

;------------ Check password --------------

	ldi		YL,ramstart
	clr		eeadr
	ldi		byte_counter,4
check_password:
	rcall	eeread
	ld		temp2,Y+
	cp		temp2,temp
	brne	check_for_recovery_password				;If is not the same, go to check it is the recovery password.
	dec		byte_counter
	brne	check_password
	rjmp	read_next

;------------ Check for recovery password --------------
check_for_recovery_password:
	ldi		YL,ramstart
	ldi		byte_counter,4
	ldi		eeadr,5	;eeprom address after '*' character.

check_next_recovery_byte:
	rcall	eeread
	ld		temp2,Y+
	cp		temp2,temp
	brne	exit_from_this_routine
	dec		byte_counter
	brne	check_next_recovery_byte
	rjmp	recovery_password
	
exit_from_this_routine:	
;	delete_received_message:
	ldi		zl,low(Delete_SMS*2)	;
	ldi		zh,high(Delete_SMS*2)	;
	rcall	send_command

exit_from_here:

	ldi		txbyte,'A'
	rcall	b_transmit
	ldi		txbyte,'T'
	rcall	b_transmit
	rjmp	Send_ESC_sequence


read_next:
;------------ Check for <password change> symbol "*" --------------

	ld		temp,Y+
	cpi		temp,'*'	;check for password change symbol "*"
	brne	read_next2

	ldi		byte_counter,4
	clr		eeadr
write_all_password_bytes_to_ram:
	ld		temp,Y+
	rcall	eewrite
	dec		byte_counter
	brne	write_all_password_bytes_to_ram

;------------ Check for relay status and arm or disarm the relays --------------
read_next2:

	clr		output
	ldi		YL,ramstart

;========
check_for_1st_relay:

	cpi		YL,252
	breq	check_for_2nd_relay
	ld		txbyte,Y+
	cpi		txbyte,'1'
	brne	check_for_1st_relay
	ld		txbyte,Y+
	cpi		txbyte,'='
	brne	check_for_1st_relay
	ld		txbyte,Y+
	cpi		txbyte,'1'
	brne	check_for_zero
	sbi		portd,Relay1
	rjmp	check_for_2nd_relay
check_for_zero:
	cpi		txbyte,'0'
	brne	check_for_2nd_relay
	cbi		portd,Relay1

;========
check_for_2nd_relay:
	ldi		YL,ramstart
check_for_2nd_relayb:

	cpi		YL,252
	breq	check_for_3rd_relay
	ld		txbyte,Y+
	cpi		txbyte,'2'
	brne	check_for_2nd_relayb
	ld		txbyte,Y+
	cpi		txbyte,'='
	brne	check_for_2nd_relayb
	ld		txbyte,Y+
	cpi		txbyte,'1'
	brne	check_for_zero2
	sbi		portd,Relay2
	rjmp	check_for_3rd_relay
check_for_zero2:
	cpi		txbyte,'0'
	brne	check_for_3rd_relay
	cbi		portd,Relay2

;========
check_for_3rd_relay:
	ldi		YL,ramstart
check_for_3rd_relayb:

	cpi		YL,252
	breq	check_for_4th_relay
	ld		txbyte,Y+
	cpi		txbyte,'3'
	brne	check_for_3rd_relayb
	ld		txbyte,Y+
	cpi		txbyte,'='
	brne	check_for_3rd_relayb
	ld		txbyte,Y+
	cpi		txbyte,'1'
	brne	check_for_zero3
	sbi		portd,Relay3
	rjmp	check_for_4th_relay
check_for_zero3:
	cpi		txbyte,'0'
	brne	check_for_4th_relay
	cbi		portd,Relay3

;========
check_for_4th_relay:
	ldi		YL,ramstart
check_for_4th_relayb:

	cpi		YL,252
	breq	check_for_status
	ld		txbyte,Y+
	cpi		txbyte,'4'
	brne	check_for_4th_relayb
	ld		txbyte,Y+
	cpi		txbyte,'='
	brne	check_for_4th_relayb
	ld		txbyte,Y+
	cpi		txbyte,'1'
	brne	check_for_zero4
	sbi		portd,Relay4
	rjmp	check_for_status
check_for_zero4:
	cpi		txbyte,'0'
	brne	check_for_status
	cbi		portd,Relay4

;------------ check	for <status> command inside the SMS ------------

check_for_status:
	ldi		YL,ramstart

check_next_byte_for_status:
	ld		txbyte,Y+
	cpi		YL,252
	breq	aaaa
	rjmp	check_for_s

aaaa:	
	rjmp	Send_ESC_sequence

check_for_s:
	cpi		txbyte,'s'
	breq	check_for_t
	cpi		txbyte,'S'
	brne	check_next_byte_for_status

check_for_t:
	ld		txbyte,Y+
	cpi		txbyte,'t'
	breq	check_for_a
	cpi		txbyte,'T'
	brne	check_next_byte_for_status
check_for_a:
	ld		txbyte,Y+
	cpi		txbyte,'a'
	breq	check_for__t
	cpi		txbyte,'A'
	brne	check_next_byte_for_status
check_for__t:
	ld		txbyte,Y+
	cpi		txbyte,'t'
	breq	check_for_u
	cpi		txbyte,'T'
	brne	check_next_byte_for_status
check_for_u:
	ld		txbyte,Y+
	cpi		txbyte,'u'
	breq	check_for__s
	cpi		txbyte,'U'
	brne	check_next_byte_for_status
check_for__s:
	ld		txbyte,Y+
	cpi		txbyte,'s'
	breq	Request_status
	cpi		txbyte,'S'
	brne	check_next_byte_for_status

;=========== read the relay's status ============
Request_status:
	ldi		zl,low(Read_received_sms*2)		; Re-read the SMS to see the phone number of the sender.
	ldi		zh,high(Read_received_sms*2)	;
	rcall	send_command
	ldi		temp2,50					;read 20 bytes
	ldi		No_Of_ignore_bytes,12		;Leave first 12 of received bytes.
	rcall	from_read_phone_number		;read again the SMS.

	ldi		zl,low(Send_SMS_command*2)	;
	ldi		zh,high(Send_SMS_command*2)	;
	rcall	send_command
	ldi		YL,ramstart + 18	;go to sender's phone number in RAM (RAM address 113) exclude the first (") symbol.
	ld		txbyte,Y+
	rcall	b_transmit
	;ldi		txbyte,'a'
	;rcall	b_transmit
	;ldi		txbyte,'t'
	;rcall	b_transmit
send_phone_number:
	ld		txbyte,Y+
	rcall	b_transmit
	cpi		txbyte,'"'
	brne	send_phone_number
	ldi		txbyte,0x0d
	rcall	b_transmit
	rcall	delay
	rcall	delay
	rcall	delay
	rcall	delay
	rcall	delay
	rcall	delay


send_nxt:
	ldi		zl,low(Relay*2)		;
	ldi		zh,high(Relay*2)	;
	rcall	send_command
	ldi		txbyte,'1'
	rcall	b_transmit
	ldi		txbyte,'='
	rcall	b_transmit
	sbic	portD,relay1
	rjmp	send_one
	ldi		txbyte,'0'
send1:
	rcall	b_transmit
	ldi		txbyte,' '
	rcall	b_transmit

	ldi		zl,low(Relay*2)		;
	ldi		zh,high(Relay*2)	;
	rcall	send_command
	ldi		txbyte,'2'
	rcall	b_transmit
	ldi		txbyte,'='
	rcall	b_transmit
	sbic	portD,relay2
	rjmp	send_one2
	ldi		txbyte,'0'
send2:
	rcall	b_transmit
	ldi		txbyte,' '
	rcall	b_transmit

	ldi		zl,low(Relay*2)		;
	ldi		zh,high(Relay*2)	;
	rcall	send_command
	ldi		txbyte,'3'
	rcall	b_transmit
	ldi		txbyte,'='
	rcall	b_transmit
	sbic	portD,relay3
	rjmp	send_one3
	ldi		txbyte,'0'
send3:
	rcall	b_transmit
	ldi		txbyte,' '
	rcall	b_transmit

	ldi		zl,low(Relay*2)		;
	ldi		zh,high(Relay*2)	;
	rcall	send_command
	ldi		txbyte,'4'
	rcall	b_transmit
	ldi		txbyte,'='
	rcall	b_transmit
	sbic	portD,relay4
	rjmp	send_one4
	ldi		txbyte,'0'
send4:
	rcall	b_transmit
	ldi		txbyte,' '
	rcall	b_transmit


;========= Read the 8 input status =========

	ldi		byte_counter,8
	in		status,pinB
	com		status				;invert	data
	ldi		no_of_relay,'1'

send_nxt2:
	ldi		zl,low(cmdOut*2)		;
	ldi		zh,high(cmdOut*2)	;
	rcall	send_command
	mov		txbyte,no_of_relay
	rcall	b_transmit
	ldi		txbyte,'='
	rcall	b_transmit
	sbrc	status,0
	rjmp	send_onee
	ldi		txbyte,'0'
send1e:
	rcall	b_transmit
	ldi		txbyte,' '
	rcall	b_transmit
	dec		byte_counter
	breq	send_message_
	ror		status
	inc		no_of_relay
	rjmp	send_nxt2

send_message_:
	ldi		txbyte,26		;<Ctrl-Z> key
	rcall	b_transmit
	ldi		txbyte,$0D
	rcall	b_transmit
	rcall	long_delay

delete_old_message:
	ldi		zl,low(Delete_SMS*2)	;
	ldi		zh,high(Delete_SMS*2)	;
	rcall	send_command
	rcall	long_delay
	rjmp	Send_ESC_sequence

send_onee:
	ldi		txbyte,'1'
	rjmp	send1e

send_one:
	ldi		txbyte,'1'
	rjmp	send1

send_one2:
	ldi		txbyte,'1'
	rjmp	send2

send_one3:
	ldi		txbyte,'1'
	rjmp	send3

send_one4:
	ldi		txbyte,'1'
	rjmp	send4
;------------ 
next:

	rjmp	loop	
;----------------------------------------------------		
send_command:
	lpm
	tst		r0				;check if it's the last character (zero number)
	breq	return			;if it is, return.
	mov		txbyte,r0
	rcall	b_transmit		;
	adiw	zl,1			;increase zl
	rjmp	send_command	;read the next character from flash memory

return:		ret


;read_response:
;	ldi		No_Of_ignore_bytes,71	;ignore first 71 bytes of received SMS (part: +CMGR: "REC READ","+306947123456",,"05/11/29,14:17:12+08"[CR][LF] )
;	rcall	from_read_phone_number	;Go to receive bytes from module
;	com		temp4
;	ret
;----------------------------------------------------
Send_ESC_sequence:
	ldi		txbyte,$1B	;escape key
	rcall	b_transmit
	ldi		txbyte,$0D
	rcall	b_transmit

	rcall	long_delay

	rjmp	start		;Read all the time the last SMS


loop:	rjmp	loop

;----------------------------------------------------
check_for_command_error:

	ldi		YL,ramstart
	ldi		byte_counter,120
read_for_next:
	dec		byte_counter
	breq	exit_from_check_error
	ld		temp,Y+
	cpi		temp,0
	breq	exit_from_check_error
	cpi		temp,'O'
	brne	read_for_next
	ld		temp,Y+
	cpi		temp,'K'
	brne	read_for_next
	ldi		temp,good
	ret

exit_from_check_error:
	ldi		temp,error	
	ret
;=============================================================
;		<Change line> and <Enter> ASCII commands
;=============================================================
;nextline:
;	ldi		txbyte,0x0d
;	rcall	b_transmit
;	ldi		txbyte,0x0a
;	rcall	b_transmit
;
;	ret
;
;***************************************************************************
; Transmiting routine (The data from the eeprom through the AVR are going to
; the PC computer)         
;***************************************************************************
b_transmit:	
	sbis	USR,UDRE	;is UART transmitter ready?
	rjmp	b_transmit
	out		UDR,txbyte	;sent out char
	ret

;*************************************************************************
; Receiving routine (The data from PC computer through to the AVR are going
; to the eeprom)  
;*************************************************************************
receive2:
	ldi		No_Of_ignore_bytes,12		;Ignore the first 12 AT command bytes.
	rjmp	from_read_phone_number
receive:	
	ldi		No_Of_ignore_bytes,1

from_read_phone_number:
	ldi		YL,RamStart					;The first byte of RAM
	clr		temp4
	clr		Byte_counter		

Delay_routine1:
	ldi		temp3,5
Delay_routine2:
	ldi		temp2,255
Delay_routine3:
	ldi		temp,255
loop2:
	sbic	USR,RXC
	rjmp	continue
	dec		temp
	brne	loop2
	dec		temp2
	brne	Delay_routine3
	dec		temp3
	brne	Delay_routine2
	rjmp	exit

continue:
	in		Rxbyte,UDR
	inc		Byte_counter
	cp		No_Of_ignore_bytes,byte_counter		
	brge	Delay_routine1
	st		Y+,RxByte
	inc		temp4
	cpi		YL,ramend-5 				;If RAM address is at 250th byte, go to exit because it will erase the "return" stack pointer. 
	breq	exit
	rjmp	Delay_routine1

exit:
	ldi		RxByte,0
	st		Y+,RxByte
	ret

;=================================================================
;               Recovery password routine
;=================================================================
recovery_password:
	ldi		YL,ramstart
	clr		eeadr
	ldi		byte_counter,4
	ldi		temp,'1'
write_next_password_number:
	rcall	eewrite
	inc		temp
	dec		byte_counter
	brne	write_next_password_number

delete_old_message2:
	ldi		zl,low(Delete_SMS*2)	;
	ldi		zh,high(Delete_SMS*2)	;
	rcall	send_command
	rcall	long_delay

	rjmp	Send_ESC_sequence			;go to send ESC sequence and then go to start.

;=================================================================
;               eeprom read routine
;=================================================================

EERead:
	out 	EEAR,eeadr		;send address to EEPROM 
	sbi 	EECR,EERE		;strobe EEPROM
	in 		temp,EEDR		;read decoded number
	inc		eeadr
	ret

;=================================================================
;               eeprom write routine
;=================================================================
EEWrite:
	sbic	EECR,EEWE		;if EEWE not clear
	rjmp	EEWrite			;    wait more

	out		EEAR,eeadr	
	out		EEDR,temp		;output data
	sbi 	EECR,EEMWE		;set master write enable
	sbi		EECR,EEWE		;set EEPROM Write strobe
 	inc		eeadr	
	ret

;=================================================================
;               Delay routine
;=================================================================

long_delay:
	ldi		delay3,100
waitmore2:
	rcall	delay
	dec		delay3
	brne	waitmore2
	ret	



delay:
	ldi		delay2,255
waitsome:
	ldi		delay1,255			

waitmore:
	dec		delay1
	brne	waitmore
	dec		delay2
	brne	waitsome
	
	ret

.eseg
;1234 is programable password. 5268 is the fixed recovery password (like PUK password).
.db	"5678*5268"

BigDog
 

Re: Difference between C & Embedded C

Which is the suitable software for simulation. What are the steps to be taken to make it work on the uC.
 

Re: Difference between C & Embedded C

I checked the manual of ATtiny2313 and it is the assembly language of ATtiny2313.
 


Can i simulate assembly language in any software.

Some IDEs like KEIL's uVision support register and port level simulation, while simulation with other device models, sensors, etc is support by simulation software like ISIS Proteus.

KEIL does offer fairly good serial port simulation, you could monitor "AT Commands" sent to an attached GSM/GPRS module.

BigDog
 

use avrstudio!

The previous reference to simulators was in general, not specifically for AVR simulation.

As ctownsend pointed out, the AVR Studio 4 IDE does offer register and stimulus level simulation.

Here are some tutorials on how to use the AVR Studio 4 Simulator:

**broken link removed**

**broken link removed**

**broken link removed**

The drawback with register and stimulus level simulators is that they do not offer simulation with other peripheral devices like the Proteus Simulator.

BigDog
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top