0% found this document useful (0 votes)
4 views4 pages

Header File

The document contains code for interfacing with an LCD, ADC, and keyboard in a microcontroller environment. It includes functions for initializing the LCD and ADC, sending data to the LCD, and scanning keyboard inputs. The code also implements delay functions for timing control in the operations.

Uploaded by

helen jenefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Header File

The document contains code for interfacing with an LCD, ADC, and keyboard in a microcontroller environment. It includes functions for initializing the LCD and ADC, sending data to the LCD, and scanning keyboard inputs. The code also implements delay functions for timing control in the operations.

Uploaded by

helen jenefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

lcd.

h:
#include <string.h>
extern void DELAY(unsigned int);
extern void LCDSTR(unsigned char ADDRESS,char *MSG);
extern void LCD_DATA(unsigned char);
extern void LCD_CD(unsigned int);
extern void LCD_INIT(void);
unsigned int E = 0x00000800; // P1.11 ENABLE LCD
unsigned int RW = 0x00000400; // P1.10 READ/WRITE LCD
unsigned int RS = 0x00000200; // P1.09 REGISTER SELECT LCD
void DELAY(unsigned int VALUE)
{
unsigned int i,j;
for(i=0;i<VALUE;i++)
{
for(j=1;j<1200;j++);
}
}
void LCD_DATA(unsigned char VALUE)
{
unsigned int b,TEMP;
TEMP = VALUE;
for(b=0;b<16;b++)
{
TEMP = TEMP<<1;
}
IO1SET = TEMP;
IO1CLR = ~TEMP;
IO0CLR = RW;
IO0SET = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCD_CMD(unsigned int LCMD)
{
unsigned int b;
for(b=0;b<16;b++)
{
LCMD = LCMD<<1;
}
IO1SET = LCMD;
IO1CLR = ~LCMD;
IO0CLR = RW;
IO0CLR = RS;
IO0SET = E;
DELAY(50);
IO0CLR = E;
}
void LCDSTR(unsigned char ADDRESS,char *MSG)
{
unsigned char COUNT,LENGTH;
LCD_CMD(ADDRESS);
LENGTH = strlen(MSG);
for(COUNT=0;COUNT<LENGTH;COUNT++)
{
LCD_DATA(*MSG);
MSG++;
}
}
void LCD_INIT()
{
IO0DIR =0x00F00E00; // P0.9 ----- P0.11 LCD DATA
IO1DIR =0X00FF0000; // P1.16 --- P1.23 LCD CONTROL
LCD_CMD(0x00000038); //function set: 8-bit, 2 line, 5x7 dots
LCD_CMD(0x0000000C); //display on, cursor off
LCD_CMD(0x00000001); //clear display screen
LCD_CMD(0x00000006); //entry mode
}

delay.h:
#include <stdint.h>
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++);
}
}

adc.h:
extern void INIT_ADC(void);
extern void PwmInit(void);
extern int READ_ADC(void);
extern void CONVERT_ADC(unsigned int);
unsigned int TEMP=0,ADC=0;
unsigned long temp_adv=0,temp_sum=0;
unsigned int count=0;
unsigned int PWM=0;
void INIT_ADC()
{
PINSEL1 |= 0x01000000;
AD0CR = 0x00200602;
}
void PWM_INIT()
{
PINSEL0 = 0X00008000; // Enable PWM2 -- P0.7
PWMLER = 0X00000004; // Set latch register
PWMPR = 0X00000000; // Prescale 0
PWMMR0 = 0X000003FF; // 120 KHz Frequency
PWMMR2 = 0X000003FF; // 50% Duty Cycle 7C 0,62,124,186
PWMMCR = 0X00000002; // Set only Match0 control
PWMPCR = 0X00000400;
PWMTCR = 0X00000009;
}
int READ_ADC()
{
int VAL;
AD0CR |= 0x01000000; /* Start A/D Conversion */
do
{
VAL = AD0DR1; /* Read A/D Data Register */
}
while (!(VAL & 0x80000000)); /* Wait for end of A/D Conversion */
AD0CR &= ~0x01000000; /* Stop A/D Conversion */
VAL >>=6;
VAL = VAL & 0x3FF;
return(VAL);
}
void CONVERT_ADC(unsigned int ADC)
{
unsigned int CNT1,CNT2,CNT3,CNT4;
unsigned char DATA1,DATA2,DATA3,DATA4;
CNT1 = ADC % 10000/1000;
CNT2 = ADC % 1000/100;
CNT3 = ADC % 100/10;
CNT4 = ADC % 10/1;
DATA1 = CNT1 | 0x30;
DATA2 = CNT2 | 0x30;
DATA3 = CNT3 | 0x30;
DATA4 = CNT4 | 0x30;
LCD_DATA(DATA1);
LCD_DATA('.');
LCD_DATA(DATA2);
LCD_DATA(DATA3);
LCD_DATA(DATA4);
return;
}
void CONVERT_ADC1(unsigned int ADC)
{
unsigned int CNT1,CNT2,CNT3,CNT4;
unsigned char DATA1,DATA2,DATA3,DATA4;
CNT1 = ADC % 10000/1000;
CNT2 = ADC % 1000/100;
CNT3 = ADC % 100/10;
CNT4 = ADC % 10/1;
DATA1 = CNT1 | 0x30;
DATA2 = CNT2 | 0x30;
DATA3 = CNT3 | 0x30;
DATA4 = CNT4 | 0x30;
LCD_DATA(DATA1);
LCD_DATA(DATA2);
LCD_DATA(DATA3);
LCD_DATA('.');
LCD_DATA(DATA4);
return;
}
keyboard.h:
#include <stdint.h>
#define C1 0X00E00000
#define C2 0X00D00000
#define C3 0X00B00000
#define C4 0X00700000
#define R1 0x000E0000
#define R2 0x000D0000
#define R3 0x000B0000
#define R4 0x00070000
#define CLR 0x00F00000
extern char scan (int);
void delay_ms(uint16_t j)
{
uint16_t x,i;
for(i=0;i<j;i++)
{
for(x=0; x<6000; x++); }
}
char scan(int keystatus) /* scanning a a key */
{
while((IO0PIN & 0X000F0000)==keystatus)
{
delay_ms(50);
if((IO0PIN & 0X000F0000)== 0X000F0000)return(1);
}
return(0) ;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy