Google

May 14, 2008

assembly Program to create , write and close file

It creates a file named trail.try and then uses function 40h to write a string of ASCII characters to the file function 3Eh is used to close file.

;named trail.try.
data segment
org 1000h
handle dw? ; reserve ram for handle variable
data ends
code segment
mov sp,6000h
mov dx,path
mov ah,03ch
mov cx,0000h
int 21h
mov handle,ax
mov bx,ax
mov ah,40h
mov cx,0005h
mov dx,msg
int 21h
mov ax,3e00h
mov bx,handle
int 21h
path: 'db' A: TRAIL.TRY',00h
msg: db 'hello'; msg to be written
code ends

You might be also interested in:

:: Data transfer instructions of 8086 microprocessor
:: 8085 Microprocessor simulator for linux
::Interfacing pic microcontroller with LCD
:: Serial Port interfacing with atmega

May 13, 2008

Program to find out the number of even and odd numbers from a given series

Program to find out the number of even and odd numbers from a given series of 16 bit hexadecimal numbers.

The simplest logic to decide whether a binary number is even or odd is to check the least significant bit of the number. If the bit is zero, the number is even, else its odd. Check the LSB by rotating the number through carry flag and increment even or odd number counter.


ASSUME CS:CODE, DS:DATA
DATA SEGMENT
LIST DW 2357H,0a579H,0c2322H,0c91eH,0c0000H,0957H
COUNT EQU 006h
DATA ENDS
CODE SEGMENT

START: XOR BX,BX
XOR DX,DX
MOV AX,DATA
MOV DS,AX
MOV CL,COUNT
MOV SI, OFFSET LIST
AGAIN: MOV AX,[SI]
RPR AX,01
JC ODD
INC BX
JMP NEXT
ODD: INC DX
NEXT: ADD SI,02
DEC CL
JNZ AGAIN
MOV AH,4CH
INC 21H
CODE ENDS
END START

You might be also interested in:
:: Data transfer instructions of 8086 microprocessor
:: 8085 Microprocessor simulator for linux
::Interfacing pic microcontroller with LCD
:: Serial Port interfacing with atmega

assembly program to find out the largest number from an unordered array

The program to find out the largest number from an unordered array of sixteen 8 bit numbers stored sequentially in the memory locations starting at offset 0500H in the segment 2000H


Logic: The 1st number of the array is taken in a register, say AL. The 2nd number of array is then compared with the 1st one. If the 1st one is greater than 2nd one, it is left unchanged. However, if the 2nd one is greater than 1st, 2nd number replaces the 1st one in the AL register. The procedure is repeated for every number in array and thus requires 15 iterations.



MOV CX, 0FH; Initialize counter for no. of iterations
MOV AX, 2000H; Initialize data segment
MOV DS, AX;
MOV SI, 0500H; Initialize source pointer
MOV AL, [SI]; Take 1st number in AL
BACK: INC SI;
CMP AL,[SI];
INC SI;
CMP AL,[SI];
JNC NEXT;
MOV AL,[SI];
NEXT: LOOP BACK; Repeat the procedure 15 times
HLT

You might be also interested in:

:: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language
:: Data transfer instructions of 8086 microprocessor

TCP/IP on PIC 18 series

TCP/IP stack is readly avalibe from Microchip.com
implement the tcp/ip or udp port in your projects using ENC28j60 from microchip, using SPI port

or try this

Go to www.microchip.com and search for

PIC18F97J60

It comes with ready TCP IP stack and it will help you...let me know if you need further information...

You might be also interested in:
:: 8051 based project for electrical students
:: free and open source 8086 Microprocessor Emulator
:: Invoke function

May 10, 2008

Serial Port interfacing with atmega

Here is the code to interface atmega32 and serial port.


.include"m32def.inc"
.org 0000
rjmp main


main: ldi r16,low(ramend)
out SPL,r16
ldi r16,high(ramend)
out SPH,r16

ldi r18,0x00
out UBRRH,r18
ldi r18,0x19 ;setting baud rate of 2400 for 1MHZ
out UBRRL,r18
ldi r19,0x18
out UCSRB,r19 ;enabling RX & TX bits
ldi r19,0x86
out UCSRC,r19 ;setting aychronous mode with 1 stop
;& 1start bit & no parity
again: rcall usart_rx
rcall usart_tx
rjmp again




usart_rx: sbis UCSRA,RXC
rjmp usart_rx
in r17,UDR

ret


usart_tx: sbis UCSRA,UDRE
rjmp usart_tx
out UDR,r17
ret

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

and set the settings in hyper terminal as

baud rate:2400
flow control:none

;********
You might be also interested in:
:: centigrade (celsius) to fahrenheit calculation for 8086 Assembly Language
:: Data transfer instructions of 8086 microprocessor


May 8, 2008

Interfacing pic microcontroller with LCD

Here is the code to interface the pic 16F877A PROCESSOR to 16x2 LCD
this is a assembly code and it is properly working just you have to modify some of the routines as per your need.
As this is in assembly it doesn't take any space and also it use 8 bit mode.







; Program Module : Debug board
; Purpose : to show the content of data bus and adress bus
; Programmed By : Kamal Kant Singh
; Date of Start : 26th june,2007
;_________________________________________________________________________



PROCESSOR 16F877A
#include"p16F877A.inc"

__CONFIG _CP_OFF & _WDT_OFF & _XT_OSC & _PWRTE_ON & _BODEN_OFF & _LVP_OFF & _DEBUG_OFF

cblock 0x0021
a1
a2
a3 ; used in sapr
a4
a5
a6 ;for macro PRINT
l1
l2
l3
w_temp
w_temp1
endc


PRINT macro label
local endom
local next_char
clrf a6
next_char
movf a6,w
call label
iorlw 0
btfsc STATUS,Z
goto endom
call send_char
incf a6,f
goto next_char
endom
endm

COMMA macro
movlw ','
call send_char
endm



en equ 2
rs equ 0
rw equ 1



org 0x0000
goto main
org 0x0004
goto main

main
movlw .20
call delayxms
banksel ADCON1
movlw 0x06
movwf ADCON1

banksel TRISA
movlw 0xFF
movwf TRISD ; port B for data bus contents while ports C,D are for address bus contents
movwf TRISB
movwf TRISC
movlw 0x30
movwf TRISA
clrf TRISE

banksel PORTB
clrf PORTB
clrf PORTD
clrf PORTC
clrf PORTE
clrf PORTA


; lcd operation
movlw 0x02
call send_cmd
call init_lcd
;entrance
movlw 0x82
call send_cmd
PRINT eklavya
check_again
movlw 0xC0
call send_cmd
PRINT address
call print_add
movlw 0xca
call send_cmd
PRINT dat
call print_dat
movlw 0xC5
call send_cmd


goto check_again




goto endop






init_lcd
movlw 0x28
call send_cmd
movlw 0x0c
call send_cmd
movlw 0x06
call send_cmd
;movlw 0x1c
;call send_cmd
return





send_cmd
movwf w_temp1
movlw 0x05
call delayxms
swapf w_temp1,w
bcf PORTE,rs
bcf PORTE,rw
movwf PORTA
bsf PORTE,en
nop
nop
bcf PORTE,en
movf w_temp1,w
movwf PORTA
bsf PORTE,en
nop
nop
bcf PORTE,en
movlw 0x03
call delayxms
return

send_char
movwf w_temp1
movlw 0x05
call delayxms
swapf w_temp1,w
bsf PORTE,rs
bcf PORTE,rw
movwf PORTA
bsf PORTE,en
nop
nop
bcf PORTE,en
movf w_temp1,w
movwf PORTA
bsf PORTE,en
nop
nop
bcf PORTE,en
movlw 0x03
call delayxms
return
print_add
movf PORTC,w
call sapr
call asc2
call send_char
movf a3,w
call asc2
call send_char
movf PORTD,w
call sapr
call asc2
call send_char
movf a3,w
call asc2
call send_char
return

print_dat
movf PORTB,w
call sapr
call asc2
call send_char
movf a3,w
call asc2
call send_char
return


sapr
movwf w_temp
andlw 0x0F
movwf a3
swapf w_temp,w
andlw 0x0F
return


delay3xms
movwf w_temp1
call delayxms
movf w_temp1,w
call delayxms
movf w_temp1,w
call delayxms
return


delayxms
movwf l1
up
call delay1ms
decfsz l1,f
goto up
return

delay1ms
movlw .62
movwf l2
delay4us
nop
decfsz l2,f
goto delay4us
return


asc2
addwf PCL,f
retlw '0'
retlw '1'
retlw '2'
retlw '3'
retlw '4'
retlw '5'
retlw '6'
retlw '7'
retlw '8'
retlw '9'
retlw 'A'
retlw 'B'
retlw 'C'
retlw 'D'
retlw 'E'
retlw 'F'

address
addwf PCL,f
retlw 'A'
retlw 'D'
retlw 'D'
retlw ':'
retlw 0

dat
addwf PCL,f
retlw 'D'
retlw 'T'
retlw ':'
retlw 0

eklavya
addwf PCL,f
retlw ' '
retlw 'E'
retlw 'k'
retlw 'l'
retlw 'a'
retlw 'v'
retlw 'y'
retlw 'a'
retlw ' '
retlw '1'
retlw '.'
retlw '0'
retlw ' '
retlw 0



endop
goto endop
end

You might be also interested in:
:: 8051 based project for electrical students
:: free and open source 8086 Microprocessor Emulator
:: Invoke function