Monday, March 6, 2006

Java for Electronics Engineers

So, I am a Java professional now.... Wow, that sounds Awesome.

After spending lots of time trying to understand what it is, joining formal training program, it comes to be a quiet simple stuff. Only thing is that, we, electronics engineers should be taught it in a different way.

Generally trainers start with JVM and OOPS concept and all.... And we poor souls get confused with lots of stuff coming simultaneously.

So, if you are an Electronics Engineer, know C and learning Java, here is something for you. Just follow me for one hour and you will know Java. Remember these six points:
  1. Java is like C.
  2. It is platform independent.
  3. It is like C, but it is not C.
  4. It is Object Oriented Programming Language.
  5. It supports Web Application Development (J2EE)
  6. It is better than C
Lets consider each point in detail:

1. Java is like C

Well, you already know C Language.
You know how to declare variables, how to write if else, switch case, methods, calling methods and all.
Its all valid for Java as well...

Let's have a code examples:

void main(){

   int i=100;
   int j =10;
   int m,n,o;
   int k = i+j;

   m = i*j;
   n = i /j;
   o = m*m/100;

   if(i==0){
      j= i*j;
   } else {
      j= k*j;
   }

   o = sum(m,n);
}


int sum(int i, int j){
   return i+j;
}


This code is valid for both C and Java... So its simple. Isn't it?



2. It is platform independent

So what does this mean? This means something but nothing to worry as a developer.

Think of C..... I use Turbo C, rum my code and get .exe file that can be executed independently even if I don't have code. right? 

Now can I execute same .exe file over Unix/Linux? Answer is NO.
So, code written for one platform is not usable for other platforms.

So if I want to reuse the code across platforms, what do I do?
Well, Java provides solution for this problem.


This is how:

Saturday, January 28, 2006

Digital Thermometer and Controller

Well Well,

So the experience of making Micromouse with Awesome and have had good hands on experience on Microcontrollers.....

So thought of making a simple application using 8051 microcontroller.

A simple Digital Thermometer and Controller.

Here it goes:


1) Use LM35 for sensing tmperature.
2) Add LM324 based signal conditioning to multiplu output of LM35 (10mV/degree Centigrade) with 1.96 to match with resolution of ADC.
3) Use ADC0809 to convert analog value to digital one.
4) Use AT89C51
5) Display temperature on 16x2 LCD
6) Use 5V relay to control Heater
7) Use ULN2003 for driving relay.

Here is circuit diagram designed in ISIS Proteus Simulator:


Created PCB in Express PCB:



Get the PCB manufactured. Solder all components and write a bit of Code:

Here it goes:



EN EQU P0.7
RS EQU P0.5
RW EQU P0.6

ADCA EQU P0.2
ADCB EQU P0.1
ADD_C EQU P0.0

TEMP EQU 08H
COUNT1 EQU 09H
COUNT2 EQU 0AH
COUNT3 EQU 0BH
SET_POINT EQU 0CH
ADC_VALUE EQU 0DH

LCD_DATA EQU P2


ORG 0000H
JMP INITIALISE


ORG 0013H
LCALL INT11
RETI

ORG 0003H
LCALL INT00
RETI


ORG 0100H

INITIALISE:
MOV SP,#30H
SETB TCON.2
SETB TCON.0
MOV IE,#10000101B
LCALL DISPLAY_WELCOME
LCALL DELAY_1
JMP MAIN

MAIN:
LCALL READ_ADC
MOV TEMP,A
INC TEMP
MOV COUNT1,#30H
MOV COUNT2,#30H
MOV COUNT3,#30H
LCALL CONVERT
LCALL LCD_DISPLAY
LCALL COMPARE
LCALL DELAY_1
JMP MAIN

DELAY_1:
MOV R4,#0AH
AAAA2:MOV R3,#0FFH
AAAA1:MOV R2,#0FFH
AAAA:DJNZ R2,AAAA
DJNZ R3,AAAA1
DJNZ R4,AAAA2
RET


COMPARE:
MOV A,SET_POINT
SUBB A,ADC_VALUE
JC NO_CHANGE
CLR P0.3
SETB P0.4
RET
NO_CHANGE:
SETB P0.3
CLR P0.4
RET

READ_ADC:
MOV A,#0FFH
MOV P1,A    ;TO MAKE P1 AS AN INPUT PORT FOR ADC DATA
SETB ADCA
SETB ADCB
CLR ADD_C
SETB P3.5  ;SET ALE HIGH
LCALL DELAY_ALE
SETB P3.0   ; SET SOC
LCALL DELAY_START
CLR P3.5
CLR P3.0
SETB P3.1
HERE1: JNB P3.1,HERE1   ;CHECKING EOC
SETB P3.4              ;SET OE
LCALL DELAY_OE
MOV A,P1
MOV ADC_VALUE, A
CLR P3.4    ;OE RESET
RET


DELAY_ALE:
DELAY_START:
DELAY_OE:
NOP
NOP
RET


DISPLAY_WELCOME:
MOV A,#38H
LCALL COMMAND
MOV A,#0EH
LCALL COMMAND
MOV A,#01H
LCALL COMMAND
MOV A,#06H
LCALL COMMAND
MOV A,#80H
LCALL COMMAND
MOV A,#"W"
LCALL DISPLAY
MOV A,#"E"
LCALL DISPLAY
MOV A,#"L"
LCALL DISPLAY
MOV A,#"C"
LCALL DISPLAY
MOV A,#"O"
LCALL DISPLAY
MOV A,#"M"
LCALL DISPLAY
MOV A,#"E"
LCALL DISPLAY
RET


LCD_DISPLAY:
MOV A,#38H
LCALL COMMAND
MOV A,#0EH
LCALL COMMAND
MOV A,#01H
LCALL COMMAND
MOV A,#06H
LCALL COMMAND
MOV A,#80H
LCALL COMMAND
MOV A,#"T"
LCALL DISPLAY
MOV A,#":"
LCALL DISPLAY
MOV A,COUNT3
LCALL DISPLAY
MOV A,COUNT2
LCALL DISPLAY
MOV A,COUNT1
LCALL DISPLAY
MOV A,#' '
LCALL DISPLAY
MOV A,#'S'
LCALL DISPLAY
MOV A,#'P'
LCALL DISPLAY
MOV A,#':'
LCALL DISPLAY
MOV TEMP,SET_POINT
MOV COUNT3,#30H
MOV COUNT2,#30H
MOV COUNT1,#30H
LCALL CONVERT
MOV A,COUNT3
LCALL DISPLAY
MOV A,COUNT2
LCALL DISPLAY
MOV A,COUNT1
LCALL DISPLAY
RET

COMMAND:
MOV LCD_DATA,A
CLR RS
CLR RW
SETB EN
CLR EN
LCALL DELAY
RET


DISPLAY:
MOV LCD_DATA,A
SETB RS
CLR RW
SETB EN
CLR EN
LCALL DELAY
RET


CONVERT:
DJNZ TEMP,ENDX 
RET
ENDX:

MOV A,COUNT1
INC A
CJNE A,#3AH,MMM
MOV A,#30H
MOV COUNT1,A

MOV A,COUNT2
INC A
CJNE A,#3AH,MMM2
MOV A,#30H
MOV COUNT2,A

MOV A,COUNT3
INC A
CJNE A,#3AH,MMM3
MOV A,#30H
MOV COUNT3,A

MMM3:
MOV COUNT3,A
JMP END_INT0
MMM2:
MOV COUNT2,A
JMP END_INT0
MMM:
MOV COUNT1,A
END_INT0:
JMP CONVERT
RET



DELAY:
MOV R3,#07H
FRFR2:MOV R4,#09FH
FRFR:DJNZ R4,FRFR
DJNZ R3,FRFR2
RET


INT11:
INC SET_POINT
RET


INT00:
DEC SET_POINT
RET

END




And yeah..... It works :-)