Archives
-
Frequency Counter (Using 8051) Calibration
Hello
I am having a problem in Calibrating the Frequency Counter.
I’ve used Counter 0 16-bit mode.
And I am actually recording values in TL0 and TH0 as the counter is run as then they are refreshed.
The problem is that TL0 and TH0 gives the values in HEX, and I am not able to implement a formula to calibrate the value, since I cannot multiply or divide the HEX values that I get from the TL0 and TH0.Please advise me some technique in C-programming on how can I “combine” TH0 and TL0 values to get values in a single variable then how can I multiply an integer to it and then how they can be converted into ASCII to be displayed on the LCD.
I am presently able to convert TL0 and TH0 into ASCII “separately” where I am feeding the LCD, the values in single digits like MSDH (Most Significant Digit for TH) MIDH (Middle Digit for TH) LSDH (Least Significant Digit for TH) MSDL (Most Significant Digit for TL) and so on…..
Please have a look at the C-Code and suggest me to improve it and to solve my problem if possible.
Thank you.
CODE:
#includeltreg51.hgt
sfr ldata = 0×90;
sbit rs=P2^0;
sbit rw=P2^1;
sbit en=P2^2;
sbit busy=P1^7;void lcdcmd(unsigned char value); //LCD Command Instruction Function Declaration
void lcddata(unsigned char value); //LCD Data Instruction Function Declaration
void MSDelay(unsigned int time); //Delay Function Declaration
void lcdready(); //Busy Flag Function Declaration
void main(void)
{
unsigned char HexL, HexH, name[5]=”Osama”;
unsigned int i, xL, xH, d1L, d1H, d2L, d2H, d3L, d3H, MSDL, MSDH, MIDL, MIDH, LSDL, LSDH;
T0=1;
TMOD=0×05; //counter 0, mode 1 (16 bits)
TL0=0; //set count to zero
TH0=0; //set count to zero
MSDelay(5);
lcdcmd(0×38); //2 lines and 5X7 matrix
lcdcmd(0x0C); //Display ON, Cursor Blinking = 0x0E But this command is Display ON, Cursor OFF
lcdcmd(0×01); //Clear Display Screen
lcdcmd(0×06); //Increament Cursor (Shift Cursor to Right)
lcdcmd(0×86);
for(i=0;ilt5;i++)
lcddata(name[i]);
MSDelay(200);
lcdcmd(0×01);
while(1)
{
do
{
TR0=1;
HexL = TL0; //Loading Value of TL0 in HexL
HexH = TH0; //Loading Value of TH0 in HexH
TL0=0; //Reset TL0
TH0=0; //Reset TH0
xL = HexL / 10; //Code for converting HEX into Decimal for TL0
d1L= HexL % 10; //LSD TL
d2L = xL % 10; //Middle TL
d3L = xL / 10; //MSD TL
xH = HexH / 10; //Code for converting HEX into Decimal for TLH
d1H= HexH % 10; //LSD TH
d2H = xH % 10; //Middle TH
d3H = xH / 10; //MSD TH
LSDL = d1L + 48; //Cconverting Decimal to ASCII
MIDL = d2L + 48;
MSDL = d3L + 48;
LSDH = d1H + 48;
MIDH = d2H + 48;
MSDH = d3H + 48;
lcddata(MSDH);
lcddata(MIDH);
lcddata(LSDH);
lcddata(MSDL);
lcddata(MIDL);
lcddata(LSDL);
lcdcmd(0×10);
lcdcmd(0×10);
lcdcmd(0×10);
lcdcmd(0×10);
lcdcmd(0×10);
lcdcmd(0×10);
MSDelay(200);
}
while(TF0==0);
TR0=0;
TF0=0;
}
}void lcdcmd(unsigned char value)
{
lcdready();
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
return;
}
void lcddata(unsigned char value)
{
lcdready();
ldata=value;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
return;
}
void lcdready()
{
busy=1;
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
return;
}
void MSDelay(unsigned int time)
{
unsigned int i,j;
for(i=0;ilttime;i++)
for(j=0;jlt1275;j++);
}Related Forum Messages
- Microcontroller coin counter with IR sensor
- Can not compile LCD code in Keil.
- LCD display of ADC value
- Frequency Counter or Meter in 8051 C
- Custom Characters on LCD 16*2 Alphanumeric display
- Problem in my project
- LCD initialization help
- GSM MODEM with 8051
- Frequency counter using 8051(with the help of external interrups:
- Please rply soon…
- Custom Characters on LCD 16*2 Alphanumeric display for Waveform generations
- [SOLVED] ADC0804 Interfacing with Micro-controller AT89C51
- Microcontroller interfacing with LCD 16×1
- PIC18F4550 with LCD 4×20 liner
- Digital Clock using DS12C887
- Input i given through switch..o/p diisplay on lcd..
- Remote notice board using gsm
- RTC12C887 Interfacing Error
- Im facing a problem with adc in lpc 2138.
- RTC 12C887 Issue with P89V51RD2
hi there I m working on coin counter project which can count the no. of coin entering in a boc. I am using at89c51,infrared led and a transistor and lcd for displaying no of counts. LCD display after i make a connection, my LCD show this results. There's no display on it. Im use this code "C Language" #includeltreg51.hgt void lcdcmd (unsigned char value); void lcddata (unsigned char value); void lcdready(); void display(unsigned char z); void MSDelay (unsigned int itime); ...I saw this code in the book and i want to try it out but keil is giving me warnings...plz suggest me to solve the problem here is the code:- #include ltreg51.hgt sfr ldata = 0x90; sbit rs = P2^0; sbit rw = P2^1; sbit en = P2^2; sbit busy = P1^7; void main() { lcdcmd(0x38); lcdcmd(0x0E); lcdcmd(0x01); lcdcmd(0x06); lcdcmd(0x86); lcddata('M'); lcddata('D'); lcddata('E'); } void lcdcmd(unsigned char value) { lcdready(); ldata = value; rs = 0; rw = 0; en = 1; MSDelay(1); en = 0; return; } void lcddata(unsigned char value) { lcdready(); ldata=value; rs = 1; rw = 0; en = 1; MSDelay(1); en = 0; return; } void lcdready() { busy = 1; rs = 0; rw = 1; while(busy==1) { en = 0; MSDelay(1); en = 1; } return; } void MSDelay(unsigned int itime) { unsigned char i,j; for(i=0;iltitime;i++) for(j=0;jlt=1275;j++); } and i am getting these errors :- Build target 'Target 1' compiling lcd.c... lcd.c(9): warning C206: ...Hi, i have written a small program wherein i change the value on Pot and see the value on the LCD. but m not able to see anything. Please help. the program is as follows. #include ltreg51.hgt sbit rd = P2^5; // for ADC sbit wr = P2^6; // for ADC sbit INTR = P2^7; // for ADC sbit rs = P2^0; // for LCD initilisation sbit rw = P2^1; // for LCD initilisation sbit en = P2^1; // for LCD initilisation sfr ldata = 0x90; //select port 1 for LCD input sfr MYDATA = 0x0B0; //select port 3 for input from ADC void MSDelay(unsigned int itime) { unsigned int i,j; for(i=0;iltitime;i++) for(j=0;jlt1275;j++); } lcdcmd(unsigned char ...I m building frequency meter till 1Mhz range. I saw the project of Ajay and got some idea. on that i m trying to bulid freq meter. I m getting the output as on LCD alphabets/ascii charaters for ex if i give 80Hz for T1 character 'P' is displaying on LCD. how to convert that P to 80. My upper limit to display is 1000000Hz(1Mhz), how can i display this on LCD CODE: #include ltreg51.hgt sbit e=P2^2; sbit rw=P2^1; sbit rs=P2^0; sbit D7=P0^7; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void lcdinit(); void checkbusy(); void main() { unsigned char val,i; ...Hi all, I saw tutorial on Custom LCD characters, from that i have used code, the following code goes like this.. #includeltreg51.hgt #includeltstring.hgt sbit rs = P2^2; sbit rw = P2^1; sbit e = P2^0; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void LCD_build(); void main() { while(1) { lcdcmd(0x38); // 2 lines 5x7 matrix. delay(20); lcdcmd(0x0e); // Display ON Cursor Blinking. delay(20); lcdcmd(0x01); // Clear Display Screen. delay(20); lcdcmd(0x06); // Increment Cursor. delay(20); LCD_build(); delay(20); } } void lcdcmd(unsigned char val) { P0=val; rs=0; rw=0; e=1; delay(1); e=0; return; } void delay(unsigned int i) { unsigned int k, l; for(k=0;klti;k++) for(l=0;llt1000;l++); } void lcddata(unsigned char val) { P0=val; rs=1; rw=0; e=1; delay(1); e=0; return; } void LCD_build() { lcdcmd(0x48); //Load the location where we want to store lcddata(0x04); //Load row 1 data lcddata(0x0E); //Load row 2 data lcddata(0x0E); //Load row 3 data lcddata(0x0E); //Load row 4 data lcddata(0x1F); ...hi , i am trying to interface i2c protocol (da1307,24crom) with 8051 , even though the code is not covered underwhile(1){ } , it gets executed infinetly , wat is the problem , pLZ help me #include ltREGX51.hgt typedef unsigned int uint ; /* i2c function n data */ sfr port = 0x90; sbit scl = P3^7; sbit sda = P3^6; void starti2c(); void stopi2c(); void rominit(); void i2cwrite(uint); void i2cread(); void mdelay(); bdata uint data1; sbit msb = data1^7; sbit lsb = data1^0; /*lcd-----------------------*/ sbit en = P3^4; sbit rs = P3^5; void lcdinit(); void lcddata(unsigned int); void lcddatachar(unsigned char *); void lcdcmd(unsigned char); void bcdtoascii(unsigned int ); void msdelay(uint ); //-------------------------------- idata uint romwrite = 0xA0; idata uint romread = 0xA1; idata uint testdata = ...Hi, I followed the tutorial for interfacing with a lcd screen but it doesn't work for me. I'm using a 18F2550 pic. here is the code that I used, can someone tell me what I'm doing wrong? void main(){ initChip(); initScreen(); busy(); while(1){ lcdData('A'); busy(); } } void lcdCmd(unsigned char item) //Function to send command to LCD { PORTB = item; rs= 0; r_w=0; en=1; en=0; busy(); } void lcdData(unsigned char item) //Function to send data to LCD { PORTB = item; rs= 1; r_w=0; en=1; en=0; busy(); } void busy() //A simple for loop for delay { unsigned char i,j; for(i=0;iltj;i++) for(j=0;jlt255;j++); } void initScreen() { lcdCmd(0x0F); // ON/OFF busy(); lcdCmd(0x38); // 8-bit interface busy(); lcdCmd(0x38); //8-bit interface busy(); lcdCmd(0x38); //8-bit interface busy(); lcdCmd(0x38); // function set busy(); lcdCmd(0x0F); //display on busy(); lcdCmd(0x01); //display clear busy(); lcdCmd(0x06); //entry mode busy(); } Also there is a condition for the screen: fosc = 270kHZ. Can ...Hi I am in starting stage of GSM modem(SIM 300). I have wriiten a code where i ll send AT to modem and modem should send OK which i want to display on LCD. I have interfaced this modem to system its working fine. CODE: #includeltreg51.hgt #includeltstring.hgt #includeltabsacc.hgt sfr port=0xB0; sbit rs = P2^2; sbit rw = P2^1; sbit e = P2^0; sbit D7 = P0^7; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void lcdinit(); void checkbusy(); char read_frm_gsm(); void lcdcmd(unsigned char val) { checkbusy(); P0=val; ...hii want a code of "frequency counter" that counts the incoming pulses following is the code having some mistakes which i dont know. kindly anybody help me in this matter. regards. code is: #include ltAT89X51.hgt # define T1 P3_2 #define RS P0_0 #define RW P0_1 #define E P0_2 #define dataline P2 void Delay(unsigned int time) { unsigned int i; unsigned int j; ...actualy iam using keil student version...and while creating hex file its showing no target created...hence no hex file....!!!!! the programme is as follows.. #includeltreg51.Hgt // header file #includeltstring.hgt sfr lcd=0x80;// port 0 for lcddata sbit rs=P2^0; sbit rw=P2^1; sbit en=P2^2; void Uart_gsm (void); void delay(unsigned char); void Recievedata(); void gsminit(void); void gsmcmdsend(unsigned char *); void lcdcmd(unsigned char cmd); void lcddata(unsigned char value); unsigned char Rx_data(void); unsigned char message[75]; unsigned char count,l; void main() { lcdcmd(0x01);//clear lcd lcdcmd(0x0e);//display on cursor on lcdcmd(0x06);//increment lcdcmd(0x38);//intialize 2 lines and 5x7 matrix lcdcmd(0x80);//first row firt coloumn lcddata('G'); lcddata('S'); lcddata('M'); delay(100); Uart_gsm(); // serial port initialization gsminit(); Recievedata(); // for recieving the data from modem } void Uart_gsm(void) { TMOD = ...Hi all i m doing project on displaying waveform(only Square wave) on Alphanumeric 16*2 display. I am doing this as calling each time functions for rising edge, falling edge , high , low etc for displaying . Now currently i am controlling this through switches for waveform displaying. Actual i am facing problem to display two characters at a time.(for one character displaying is working fine) can any one suggest any other solution for this problem. for your ref i have attached my code here. #includeltreg51.hgt #includeltstring.hgt sbit hertz1 = P3^0; sbit hertz2 = P3^1; sbit hertz4 = P3^2; sbit rs = P2^2; sbit rw = P2^1; sbit e ...Hello.. I am very new to ADC Programming.... ADC.PNG The Above figure is my ADC 0804 Interfacing with AT89C51. I want to make a voltmeter which measures the voltage and display it on LCD like 3.3V means in voltage . But i am unable to do so... Here is my Code.. #include ltREGX51.Hgt #includeltstring.hgt sbit INTR = P3^5; sbit RD_ADC = P2^4; sbit WR_ADC = P2^3; sfr MYDATA = 0x80; //Port-0 sfr LcdData = 0x90; //Port-1 sbit RS = P2^5; sbit RW = P2^6; sbit EN = P2^7; void lcdcmd(unsigned char value); void lcddata(unsigned char value); void lcdstr(unsigned char msg[]); void Delay(unsigned int itime); void SerTX(unsigned char x); void main() { unsigned char value,d1,d2,d3,x; MYDATA = 0xFF; //Making P1 as Input Port INTR = 1; RD_ADC ...I am doing a microcontroller project which utilizing AT 89S52 and a LCD 16x1. I have problem when trying to display letter of 'N' to the LCD. I could have the display on the LCD display but it only give me the LCD backlight and show me the black boxes. My microcontroller is tested fine. Below is the codes that I programmed into my microcontroller Code: //Program to test LCD. Display single character "A" #include<reg51.h> #define cmdport P3 #define dataport P2 #define q 100 sbit rs = cmdport^0; //register select pin sbit rw = cmdport^1; // read write pin sbit e = cmdport^6; //enable pin void delay(unsigned ...[b]WE have this project, interfacing the PIC18f4550 with the GSM module and with LCD, we use MikroC for us to have an easy program the code, but the problem that we have is that, we tried to burn the code in the Proteus just a simple letter 'A', and the code that we have is here: //Program to test LCD. Display single character "A" sbit LCD_RS at RB5_bit; sbit LCD_EN at RB4_bit; sbit LCD_D4 at RB0_bit; sbit LCD_D5 at RB1_bit; sbit LCD_D6 at RB2_bit; sbit LCD_D7 at RB3_bit; sbit LCD_RW at RB6_bit; sbit LCD_RS_Direction at TRISB5_bit; sbit LCD_EN_Direction at TRISB4_bit; sbit LCD_D4_Direction at TRISB0_bit; sbit LCD_D5_Direction at TRISB1_bit; sbit LCD_D6_Direction at TRISB2_bit; sbit LCD_D7_Direction ...I have written the code in Assembly Language to build a Digital Clock using DS12C887...But I am facing a problem in getting the exact output... Initially as i set time i get output as (HH:MM:SS format) 16:58:01 16:58:02 03:03:03 58:58:04 and so on The out put is very much unpredictable...please help me out The code for the program appears as below... I HAVE ALSO TRIED THE RTC CODE IN ENGINEERSGARAGE BUT IT ALSO DONT WORK AT MY END...... #includeltreg51.hgt #includeltabsacc.hgt #define port P3 #define lcd_dataport P2 // lcd_dataport for lcd #define ...hi every one, i give input through switch if its high means display 1 on lcd if its low means display 0 on lcd.... i done the program it execute correctly....but in Proteus the lcd display show nothing....but i connect in led it work correctly...i think i do some mistake in my program pls any one can help me .... PHP Code: #if defined(__PCH__) #include lt18F452.hgt #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock=20000000) #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) #endif #define RS PIN_C0 #define RW PIN_C1 #define EN PIN_C2 void lcdcmd(unsigned char cmd); void lcddata(unsigned char dat); void main() { int x; set_tris_b(0x00); set_tris_a(0xff); ...dear friends, i wish to do a project.the description is the message sent should be received by the GSM modem and it should be displayed in the lcd. Iam using P89V51RD2,SIM300,16X2 LCD.the following is the code which iam using.but it is not working. what changes shud i make to work it properly...........? #includeltreg51.hgt #includeltstring.hgt #includeltabsacc.hgt #includeltstdlib.hgt #define buffer 110 sfr port=0xB0; sbit rs = P2^2; sbit rw = P2^1; sbit e = P2^0; sbit D7 = P3^7; sbit LED = P2^3; void delay(unsigned int i); void lcdcmd(unsigned char val); void lcddata(unsigned char val); void lcdinit(); void checkbusy(); void lcdstr(unsigned char *s); void tx0(unsigned char); void SMSString(char*text) ; void init(); void clear(void); void read_text(unsigned char * , unsigned char * , unsigned char *); void read_notification(); void ...I have written the code in C Language to build a Digital Clock using DS12C887 and a 16*2 LCD...But I am facing a problem in getting the exact output... Initially as i set time i get output as (HH:MM:SS format) 16:58:01 and get the outputs as 16:58:02 03:03:03 58:58:04 and so on but not in unique pattern... The out put is very much unpredictable...please help me out The code for the program appears as below... Code: #include<reg51.h> #include<absacc.h> #define port P3 #define lcd_dataport P2 // lcd_dataport for lcd #define keypad P1 // Port for keypadpad #define timeport P0 // Port for RTC sbit rs = port^0; sbit rw = port^1; sbit en = port^2; sbit key0=keypad^0; sbit key1=keypad^1; sbit key2=keypad^2; sbit ...The output is varying continously in my lcd even there is no change in the adc input.i want a code to display the output in lcd.please give any suggestions to my code. #include ltlpc21xx.hgt /* LPC2200 definitions */ #include ltstdio.hgt /* standard I/O .h-file */ //#define VREF 3 int i,j; long val,adc_val; unsigned char d1=0,d2=0,d3=0,d4=0,d5=0,d6=0; //extern void init_serial (void); void delay(void); void adc_init(void); void adc_read(void); void data(void); void lcddata(unsigned char c); void lcdcmd(unsigned char c); void lcdinit(void); void lcddisplay(unsigned char *ptr); void message(unsigned char k,unsigned char *ptr1); int main() { PINSEL0=0X00000000; PINSEL1=0X00400000; IODIR0=0X70000000; IODIR1=0X00ff0000; lcdinit(); delay(); //lcdcmd(0x01); //delay(1000); message(0x80,"ir measurement"); adc_init(); while(1) { adc_read(); data(); delay(); } } void adc_init(void) { //PINSEL1=0x01000000; ADCRamp=0x00000000; VPBDIV = 0x02; /*Set the Pclk to 30 Mhz */ ADCR|= 0x00210601; } void ...I have Interfaced 12C887 with P89V51RD2 but the time update does not occur. However the same code when burned in AT89C51, works perfectly...But due to memory restrictions of 4Kb in the Later, we have to use the former. Please help me out on this issue, ASAP! The Code is : Code: #include <p89v51rd2.h> #include<absacc.h> #define port P3 #define lcd_dataport P2 // lcd_dataport for lcd #define keypad P1 // Port for keypadpad #define timeport P0 // Port for RTC sbit rs = port^0; sbit rw = port^1; sbit en = port^5; int hr, min, sec; unsigned char a[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59}; void delay(unsigned int msec) //Time delay function { int i,j ; for(i=0;i<msec;i++) for(j=0;j<1275;j++); } void lcdcmd(unsigned char ...
