0% found this document useful (0 votes)
115 views

Assignment 4

This document contains C code that defines tasks for an embedded system to read analog to digital converter (ADC) values, display the values on an LCD screen, and read inputs from a keyboard. It includes function declarations and definitions for initializing peripherals like the LCD and keyboard, reading the ADC, printing values to the LCD, and scanning the keyboard. The main function creates four tasks to handle ADC sampling, LCD display updating, keyboard scanning, and displaying ADC values on the LCD.

Uploaded by

Sameer Kohok
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Assignment 4

This document contains C code that defines tasks for an embedded system to read analog to digital converter (ADC) values, display the values on an LCD screen, and read inputs from a keyboard. It includes function declarations and definitions for initializing peripherals like the LCD and keyboard, reading the ADC, printing values to the LCD, and scanning the keyboard. The main function creates four tasks to handle ADC sampling, LCD display updating, keyboard scanning, and displaying ADC values on the LCD.

Uploaded by

Sameer Kohok
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include "includes.

h"
#include "edutech.h"
int key_press[5][5]={0x31,0x32,0x33,0x34,0x35,
0x36,0x37,0x38,0x39,0x30,
0x41,0x44,0x2b,0x2a,0x24,
0x42,0x45,0x2d,0x2f,0x25,
0x43,0x46,0x3d,0x2e,0x26
};

void Print_Int_to_Char(unsigned int rx);


unsigned static int adcdata;

OS_STK Task1Stack[100];
void LCDDisplay(void *pdata);

OS_STK Task2Stack[256];
void ADC(void *pdata);

OS_STK Task3Stack[56];
void ADCDisplay(void *pdata);

OS_STK Task4Stack[56];
void Keyboard(void *pdata);

int main (void)


{
key_init();
lcd_init();
lcd_cmd(0x01);
lcd_init();
VPBDIV = 0x01;
DisplayRow2("ADC");
lcd_dat(':');
lcd_cmd(0xc8);
lcd_dat('K');
lcd_dat('e');
lcd_dat('y');
lcd_dat(':');
OSInit();

OSTaskCreate(ADC, (void *)0, &Task2Stack[255], 0);


OSTaskCreate(LCDDisplay, (void *)0, &Task1Stack[99], 1);
OSTaskCreate(Keyboard, (void *)0, &Task4Stack[55], 2);
OSTaskCreate(ADCDisplay, (void *)0, &Task3Stack[55], 3);
OSStart();
return 0;
}

void LCDDisplay(void *pdata)


{

int var=0x41;
timer_init();
while(1)
{
lcd_cmd(0xc0);
OSTimeDlyHMSM(0, 0, 2, 0);
lcd_cmd(0x80);
lcd_dat(var);
var++;
if(var==0x5b)
{
var=0x41;
}
}
}

void ADC(void *pdata)


{

while(1)
{
OSTimeDlyHMSM(0, 0, 0,50);
PINSEL1 |= 0x40000;
AD0CR = 0x01200310; // ad0.4
while((AD0DR & 0x80000000)!=0x80000000)
{
}
adcdata = (AD0DR>>6)&(0x003ff);
}
}

void ADCDisplay(void *pdata)


{

while(1)
{
OSTimeDlyHMSM(0, 0, 1,200);
lcd_cmd(0xc4);
Print_Int_to_Char(adcdata);
}

void Keyboard (void *pdata)


{
int col,data,row;
while(1)
{
if(key_pressed())
{
data=key_detect();
row=data/10;
col=data%10;
lcd_cmd(0xC0);
lcd_dat(key_press[row][col]);
while(!(all_key_open()))
{
}
}
}

You might also like