0% found this document useful (0 votes)
64 views3 pages

Code

This document contains C# code for a Windows Forms application. It defines methods for toggling text labels and generating code based on user input values. The generateCode method calculates a timer value based on frequency inputs, then outputs initialization and sampling code using the timer and calculated values.

Uploaded by

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

Code

This document contains C# code for a Windows Forms application. It defines methods for toggling text labels and generating code based on user input values. The generateCode method calculates a timer value based on frequency inputs, then outputs initialization and sampling code using the timer and calculated values.

Uploaded by

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

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

int btnToggled = 0;
private void ChangeText(object sender, EventArgs e)
{
if (btnToggled == 0)
{
inputLabel2.Text = "Freq:";
shifter.Text = "Time";
selection.Visible = false;
unitFreq.Visible = true;
btnToggled = 1;
}
else
{
inputLabel2.Text = "Time:";
shifter.Text = "Freq";
selection.Visible = true;
unitFreq.Visible = false;
btnToggled = 0;
}
}

private void generateCode(object sender, EventArgs e)


{
int val1 = Convert.ToInt32(inputFosc.Text);
int val2 = Convert.ToInt32(inputTorF.Text);
int val3 = (btnToggled == 0 ? selection.SelectedIndex : 3);
int val4 = 0, temp = 0;
bool hmmm;
double result, ticks;
String yep = "";

ticks = 4 / (double)val1;
switch (val3)
{
case 1: result = (double)val2 / 1000;
break;
case 2: result = (double)val2 / 1000000;
break;
case 3: result = 1 / (double)val2;
break;
default: result = (double)val2;
break;
}

hmmm = false;
for (int x = 0; x < 9; x++)
{
temp = (temp == 0 ? 1 : temp * 2);
if (ticks * 65535 * temp < result)
{
continue;
}
else
{
val4 = (int)(result / (ticks * temp));
val3 = x;
hmmm = true;
break;
}
}

switch (val3)
{
case 0:
yep = "8";
break;
case 1:
yep = "0";
break;
case 2:
yep = "1";
break;
case 3:
yep = "2";
break;
case 4:
yep = "3";
break;
case 5:
yep = "4";
break;
case 6:
yep = "5";
break;
case 7:
yep = "6";
break;
case 8:
yep = "7";
break;
}

if (hmmm)
{
outputCode.Text = "//initialization\n\n"
+ "void TMR0_init() {\n"
+ "\tT0CON = 0x8" + yep + ";\n"
+ "\tsetTMR0(0);\n"
+ "}\n\n"
+ "int getTMR0() {\n"
+ "\tint x = TMR0H << 8;\n"
+ "\tx = x + TMR0L;\n"
+ "\treturn x;\n"
+ "}\n\n"
+ "void setTMR0(int a) {\n"
+ "\tTMR0L = a;\n"
+ "\tTMR0H = a >> 8;\n"
+ "}\n\n"
+ "void sampleProg() {\n"
+ "\tTMR0_init();\n"
+ "\tif (getTMR0() > " + val4 + ") {\n"
+ "\t\t//your code\n\n"
+ "\t\tsetTMR0(0);\n"
+ "\t}\n"
+ "}";
}
else
{
outputCode.Text = "Cannot generate code.";
}
}
}
}

You might also like