jignesh doshi
Full Member level 2
- Joined
- Aug 11, 2011
- Messages
- 131
- Helped
- 2
- Reputation
- 4
- Reaction score
- 2
- Trophy points
- 1,298
- Activity points
- 2,112
I can go in ISR but i can't take data from their...what i have to do?
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 /* Declare global variable like this */ volatile int u32_gvar = 0; /* use it in interrupt handler like this */ interrupt_Handle() { /* Assign the data to global variable like this*/ u32_gvar = temp; //temp is any local data } int main() { /* you can use that data here for your operation */ u32_gvar++; // it is some example operation }
I have to write Return Statement in each and every subroutine for go back to main routine?
I want to do SPI communication using AT89C55WD Microcontroller using C language.
please give me some example code without SPI register (using GPIO pin).
void main()
{
lcd_ini();
lcd_command(0x01);
delay(5);
initiate_adc();
while(1)
{
cycle_count();
lcd();
}
}
void cycle_count()
{
command = 0x0A;
read_adc();
}
void read_adc()
{
cs1 = 1;
sclk = 0;
sdelay(0);
cs1 = 0;
sdelay(0);
ACC = command;
write_adc1();
sdi = 1;
read_adc1();
adc24 = ACC;
sdi = 1;
read_adc1();
adc16 = ACC;
sdi = 1;
read_adc1();
adc8 = ACC;
sdi = 1;
sdelay(0);
cs1 = 1;
sdelay(0);
}
void read_adc1()
{
int i;
ACC = 0x00;
for(i=0;i<7;i++)
{
lsb = sdo;
ACC = ACC << 1;
sclk = 1;
sdelay(0);
sclk = 0;
}
lsb = sdo;
ACC = ACC << 1;
sdi = 0;
sclk = 1;
sdelay(0);
sclk = 0;
}
void write_adc1()
{
int i;
for(i=0;i<8;i++)
{
sdi = ACC^7;
sclk = 1;
sdelay(0);
sclk = 0;
ACC = ACC << 1;
}
}
void write_adc()
{
cs1 = 1;
sclk = 1;
sdelay(0);
cs1 = 0;
sdelay(0);
sclk = 0;
ACC = command;
write_adc1();
ACC = adc24;
write_adc1();
ACC = adc16;
write_adc1();
ACC = adc8;
write_adc1();
sdi = 1;
sdelay(0);
cs1 = 1;
sdelay(0);
}
void initiate_adc()
{
command = 0xff;
adc24 = 0xff;
adc16 = 0xff;
adc8 = 0xfe;
write_adc();
command = 0x40;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x81;
write_adc();
command = 0x4a;
adc24 = 0x00;
adc16 = 0x03;
adc8 = 0xe8;
write_adc();
command = 0x78;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x1e;
write_adc();
command = 0x40;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x71;
write_adc();
command = 0x74;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x00;
write_adc();
command = 0x5E;
adc24 = 0xff;
adc16 = 0xff;
adc8 = 0xff;
write_adc();
}
I believe you did, but why no showing the complete code?I have define all the variable...
#include <AT89X55.H>
#include <MATH.H>
//#include <lcd.h>
sfr lcd_data_pin=0xA0; // data port P2
sbit rs=P3^7; // Register select pin
sbit rw=P3^6; // Read write pin
sbit en=P3^5; // Enable pin
sbit power_hz=P1^0; // Frequency Count
sbit cs1=P1^1; // Chip Select Pin for ADC
sbit sdo=P1^4; // SDO pin for ADC
sbit sclk=P1^5; // SCLK pin for ADC
sbit sdi=P1^6; // SDI pin for ADC
sbit lsb=ACC^0;
char bdata swich;
sbit enter = swich^0;
sbit right = swich^1;
sbit up = swich^2;
sbit set = swich^3;
volatile long a,c,rpm_count,rpm,frequency;
volatile char page_count,lo_count,pulse_ov,pulse_count;
volatile char rotate_cur,adc24,adc16,adc8,command;
volatile char eprom,eprom8,eprom16,eprom24,eprom32;
unsigned long d;
unsigned char d1,d2,d3,d4,d5,d6,d7,d8;
void dis_2();
void dis_3();
void dis_kgm();
void dis_po();
void dis_crpm();
void dis_freq();
void jump();
void write_adc1();
void write_adc(const unsigned char);
void read_adc(const unsigned char);
void delay(unsigned int msec) //delay function
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void sdelay(unsigned int msec) //delay function
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1;j++);
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp) // function to send data on LCD
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_dataa(unsigned char *disp) // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to inisialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0C);
delay(5);
}
// void _16_add()
// {
// unsigned int c,d;
// unsigned char a=0xFF,b=0xFF,d1,d2,d3,d4,d5;
// c = 0x01;
// d = c/10;
// d1 = c%10; // LSB
// c = d/10;
// d2 = d%10; // LSB-1
// d = c/10;
// d3 = c%10; // LSB-2
// c = d/10;
// d4 = d%10; // MSB+1
// d5 = d/10; // MSB
// d1 = d1+0x30;
// d2 = d2+0x30;
// d3 = d3+0x30;
// d4 = d4+0x30;
// d5 = d5+0x30;
// lcd_command(0x0C);
// delay(5);
// lcd_command(0x80);
// delay(5);
// lcd_data_pin=d5;
// en=1;
// rs=1;
// rw=0;
// delay(1);
// en=0;
// lcd_data_pin=d4;
// en=1;
// rs=1;
// rw=0;
// delay(1);
// en=0;
// lcd_data_pin=d3;
// en=1;
// rs=1;
// rw=0;
// delay(1);
// en=0;
// lcd_data_pin=d2;
// en=1;
// rs=1;
// rw=0;
// delay(1);
// en=0;
//
// lcd_data_pin=d1;
// en=1;
// rs=1;
// rw=0;
// delay(1);
// en=0;
// }
void hz()
{
TH2 = 0x00;
TL2 = 0x00;
while(power_hz == 0)
{
}
while(power_hz == 1)
{
}
TR2 = 1;
while(power_hz == 0)
{
}
while(power_hz == 1)
{
}
// while(power_hz == 0)
// {
// }
// while(power_hz == 1)
// {
// }
// while(power_hz == 0)
// {
// }
// while(power_hz == 1)
// {
// }
TR2 = 0;
}
void bitsep16()
{
d = c/10;
d1 = c%10; // LSB
c = d/10;
d2 = d%10; // LSB-1
d = c/10;
d3 = c%10; // LSB-2
c = d/10;
d4 = d%10; // MSB+1
d = c/10;
d5 = c%10; // MSB
c = d/10;
d6 = d%10; // MSB+1
d = c/10;
d7 = c%10;
d8 = c%10;
d1 = d1+0x30;
d2 = d2+0x30;
d3 = d3+0x30;
d4 = d4+0x30;
d5 = d5+0x30;
d6 = d6+0x30;
d7 = d7+0x30;
d8 = d8+0x30;
}
void lcd()
{
// c = a;
c = rpm;
bitsep16();
lcd_command(0xC0);
delay(5);
lcd_data_pin=d8;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d7;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d6;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d5;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
c = frequency;
bitsep16();
lcd_data_pin=0x46;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_pole()
{
lcd_command(0x80);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x45;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4E;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x54;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x45;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x52;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x50;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4F;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4C;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x45;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; // ahiya pole data move karavo
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_cal()
{
lcd_command(0x80);
delay(5);
lcd_data_pin=0x57;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x41;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4E;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x54;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x43;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x41;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4c;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x49;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x42;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x52;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x41;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x54;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x49;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4F;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4E;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; // ahiya pole data move karavo
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_psw()
{
lcd_command(0x80);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='N';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='R';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='P';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='A';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='S';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='S';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='W';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='O';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='R';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='D';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; // ahiya pole data move karavo
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_al()
{
lcd_command(0x80);
delay(5);
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='N';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='R';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='A';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='R';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='M';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='L';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='N';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='G';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='H';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; // ahiya pole data move karavo
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_kg()
{
lcd_command(0x80);
delay(5);
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='N';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='R';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='S';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='D';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='W';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='E';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='I';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='G';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='H';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin='T';
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; // ahiya pole data move karavo
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void increment()
{
}
void enter1()
{
}
void rotate()
{
}
void ISR_Extern0(void) interrupt 0
{
swich = P0;
swich = ~swich;
EX0 = 0;
}
void key_press()
{
if(swich != 0)
{
if(set == 1)
{
mode: swich = 0;
lo_count = lo_count+1;
if(lo_count == 1)
{
rotate_cur = 0x00;
dis_pole();
pole: EX0 = 1;
while(INT0 == 1)
{
}
while(INT0 == 0)
{
}
if(set == 1)
{
goto mode;
}
if(up == 1)
{
increment();
}
if(enter == 1)
{
enter1();
}
goto pole;
}
else if(lo_count == 2)
{
dis_cal();
cal: EX0 = 1;
while(INT0 == 1)
{
}
while(INT0 == 0)
{
}
if(set == 1)
{
goto mode; // ahiya mode ni jagya e out kari ne out nu routine call karavanu rehase.
}
if(enter == 1)
{
enter1();
}
goto cal;
}
else if(lo_count == 3)
{
rotate_cur = 0x00;
dis_psw();
psw: EX0 = 1;
while(INT0 == 1)
{
}
while(INT0 == 0)
{
}
if(set == 1)
{
goto mode;
}
if(up == 1)
{
increment();
}
if(right == 1)
{
rotate();
}
if(enter == 1)
{
enter1();
}
goto psw;
}
else if(lo_count == 4)
{
rotate_cur = 0x00;
dis_al();
al: EX0 = 1;
while(INT0 == 1)
{
}
while(INT0 == 0)
{
}
if(set == 1)
{
goto mode;
}
if(up == 1)
{
increment();
}
if(right == 1)
{
rotate();
}
if(enter == 1)
{
enter1();
}
goto al;
}
else if(lo_count == 5)
{
rotate_cur = 0x00;
dis_kg();
kg: EX0 = 1;
while(INT0 == 1)
{
}
while(INT0 == 0)
{
}
if(set == 1)
{
goto mode;
}
if(up == 1)
{
increment();
}
if(right == 1)
{
rotate();
}
if(enter == 1)
{
enter1();
}
goto kg;
}
else
{
lo_count = 0;
IT0 = 1;
IE0 = 1;
EX0 = 1;
EA = 1;
goto up;
}
}
else if(up == 1)
{
EX0 = 0;
up = 0;
page_count = page_count+1;
up: if(page_count == 1)
{
dis_2();
return;
}
else
{
page_count = 0;
dis_3();
return;
}
}
else if(right == 1)
{
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x43;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
else if(enter == 1)
{
enter = 0;
while (P0_0 == 0)
{
}
while (P0_0 == 1)
{
EX0 = 1;
if(up == 1)
{
EX0 = 0;
up = 0;
page_count = page_count+1;
if(page_count == 1)
{
dis_2();
}
else
{
page_count = 0;
dis_3();
}
}
}
while (P0_0 == 0)
{
enter = 0;
}
}
else
{
IT0 = 1;
IE0 = 1;
EX0 = 1;
EA = 1;
}
}
else
{
IT0 = 1;
IE0 = 1;
EX0 = 1;
EA = 1;
}
}
void dis_3()
{
dis_kgm();
dis_po();
return;
}
void dis_2()
{
dis_crpm();
dis_freq();
return;
}
void dis_kgm()
{
lcd_command(0x80);
delay(5);
lcd_data_pin=0x54; //1
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //2
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //3
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //4
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E; //5
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //6
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //7
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //8
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start RPM display
lcd_data_pin=0x52; //9
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //10
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //11
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //12
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //13
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //14
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //15
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start pole display
lcd_data_pin=0x20; //16
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_po()
{
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x50; //1
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //2
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //3
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //4
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E; //5
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //6
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //7
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //8
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start Slip display
lcd_data_pin=0x53; //9
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //10
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //11
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //12
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E; //13
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //14
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //15
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start Hold Display
lcd_data_pin=0x20; //16
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_crpm()
{
lcd_command(0x80);
delay(5);
lcd_data_pin=0x43; //1
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //2
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //3
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //4
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //5
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //6
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //7
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //8
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start RPM display
lcd_data_pin=0x52; //9
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //10
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //11
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //12
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //13
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //14
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //15
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start pole display
lcd_data_pin=0x20; //16
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void dis_freq()
{
c = frequency;
bitsep16();
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x46; //1
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //2
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //3
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //4
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E; //5
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //6
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //7
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20; //8
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start Slip display
lcd_data_pin=0x53; //9
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a; //10
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4; //11
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3; //12
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x2E; //13
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2; //14
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1; //15
en=1;
rs=1;
rw=0;
delay(1);
en=0;
// start Hold Display
lcd_data_pin=0x20; //16
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void ISR_Timer0(void) interrupt 1
{
TF0 = 0x00;
pulse_count = pulse_count+1;
if (pulse_count == 1)
{
TH1 = 0x00;
TL1 = 0X00;
TR1 = 1;
}
else
{
TR1 = 0;
TR0 = 0;
pulse_count = 0;
pulse_ov = 0;
}
}
void ISR_Timer1(void) interrupt 3
{
TF1 = 0;
pulse_ov = pulse_ov+1;
return;
}
void rpm_start()
{
ET1 = 1;
ET0 = 1;
EA = 1;
TR0 = 1;
}
// void write_adc1()
// {
// int i;
// for(i=0;i<8;i++)
// {
// sdi = ACC^7;
// sclk = 1;
// sdelay(1);
// sclk = 0;
// ACC = ACC << 1;
// }
// return;
// }
// void write_adc()
// {
// cs1 = 1;
// sclk = 1;
// sdelay(1);
// cs1 = 0;
// sdelay(3);
// sclk = 0;
// ACC = command;
// write_adc1();
// ACC = adc24;
// write_adc1();
// ACC = adc16;
// write_adc1();
// ACC = adc8;
// write_adc1();
// sdi = 1;
// sdelay(2);
// cs1 = 1;
// sdelay(2);
// return;
// }
void write_adc(const unsigned char regAddr)
{
unsigned char SPICount;
unsigned char SPIData;
cs1 = 1;
sclk = 0;
SPIData = 0x40;
cs1 = 0;
for (SPICount = 0; SPICount < 8; SPICount++)
{
if (SPIData & 0x80)
sdi = 1;
else
sdi = 0;
sclk = 1;
sclk = 0;
SPIData <<= 1;
}
cs1 = 1;
sdi = 0;
}
void initiate_adc()
{
// command = 0xff;
// adc24 = 0xff;
// adc16 = 0xff;
// adc8 = 0xfe;
write_adc(0xff);
write_adc(0xff);
write_adc(0xff);
write_adc(0xfe);
// command = 0x40;
// adc24 = 0x00;
// adc16 = 0x00;
// adc8 = 0x81;
write_adc(0x40);
write_adc(0x00);
write_adc(0x00);
write_adc(0x81);
// command = 0x4a;
// adc24 = 0x00;
// adc16 = 0x0f;
// adc8 = 0xa0;
// command = 0x78;
// adc24 = 0x00;
// adc16 = 0x00;
// adc8 = 0x1e;
write_adc(0x78);
write_adc(0x00);
write_adc(0x00);
write_adc(0x1e);
/* command = 0x40;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x71;
write_adc(); */
write_adc(0x40);
write_adc(0x00);
write_adc(0x00);
write_adc(0x71);
/* command = 0x74;
adc24 = 0x00;
adc16 = 0x00;
adc8 = 0x00;
write_adc(); */
write_adc(0x74);
write_adc(0x00);
write_adc(0x00);
write_adc(0x00);
/* command = 0x5E;
adc24 = 0xff;
adc16 = 0xff;
adc8 = 0xff;
write_adc(); */
write_adc(0x5e);
write_adc(0xff);
write_adc(0xff);
write_adc(0xff);
write_adc(0x4a);
write_adc(0x00);
write_adc(0x03);
write_adc(0xe8);
return;
}
/* void read_adc1()
{
int i;
ACC = 0x00;
for(i=0;i<7;i++)
{
lsb = sdo;
ACC = ACC << 1;
sclk = 1;
// sdelay(1);
sclk = 0;
}
lsb = sdo;
ACC = ACC << 1;
sdi = 0;
sclk = 1;
// sdelay(1);
sclk = 0;
return;
} */
/* void read_adc()
{
// sclk = 1;
cs1 = 1;
// sdelay(1);
cs1 = 0;
// sdelay(3);
sclk = 0;
write_adc(0x0A);
sdi = 1;
read_adc1();
adc24 = ACC;
sdi = 1;
read_adc1();
adc16 = ACC;
sdi = 1;
read_adc1();
adc8 = ACC;
sdi = 1;
// sdelay(2);
cs1 = 1;
// sdelay(2);
return;
} */
void read_adc(const unsigned char regAddr)
{
unsigned char SPICount;
unsigned char SPIData;
cs1 = 1;
sclk = 0;
SPIData = regAddr;
cs1 = 0;
for (SPICount = 0; SPICount < 8; SPICount++)
{
if (SPIData & 0x80)
sdi = 1;
else
sdi = 0;
sclk = 1;
sclk = 0;
SPIData <<= 1;
}
sdi = 1;
ACC = 0;
for (SPICount = 0; SPICount < 7; SPICount++)
{
lsb = sdo;
sclk = 1;
ACC <<= 1;
sclk = 0;
}
lsb = sdo;
// ACC <<= 1;
sdi = 0;
sclk = 1;
sclk = 0;
sdi = 1;
adc24 = ACC;
// sdi = 1;
ACC = 0;
for (SPICount = 0; SPICount < 7; SPICount++)
{
lsb = sdo;
ACC <<= 1;
sclk = 1;
sclk = 0;
}
lsb = sdo;
// ACC <<= 1;
sdi = 0;
sclk = 1;
sclk = 0;
sdi = 1;
adc16 = ACC;
// sdi = 1;
ACC = 0;
for (SPICount = 0; SPICount < 7; SPICount++)
{
lsb = sdo;
ACC <<= 1;
sclk = 1;
sclk = 0;
}
lsb = sdo;
// ACC <<= 1;
sdi = 0;
sclk = 1;
sclk = 0;
sdi = 1;
adc8 = ACC;
// sdi = 1;
cs1 = 1;
return;
}
void cycle_count()
{
read_adc(0x0a);
rpm = (65536 * adc24) + (256 * adc16) + adc8;
frequency = 0x3e8;
return;
}
void main()
{
lcd_ini();
// TMOD = 0x16;
// T2CON = 0x01;
// lcd_welcome();
// delay(300);
// IT0 = 1;
// IE0 = 1;
// EX0 = 1;
// TH0 = 0xff;
// EA = 1;
lcd_command(0x01);
delay(5);
// dis_3();
initiate_adc();
while(1)
{
// hz();
// rpm_start();
cycle_count();
// key_press();
// EX0 = 1;
// dis_3();
lcd();
}
}