?? main.c
字號:
#include "hardware.h"
#include "LCD1602.h"
extern void (enable_timer1)();
extern void (enable_timer0)();
extern void (init_LCD1602)();
extern bit cur_signal;
extern unsigned int data freq;
/* 方波占空比 */
extern unsigned char data time_high, time_low;
/* 與方波頻率相關 */
extern unsigned char data rect_high_TH0;
extern unsigned char data rect_high_TL0;
extern unsigned char data rect_low_TH0;
extern unsigned char data rect_low_TL0;
/* 正弦頻率相關 */
extern unsigned char data sin_TH0;
extern unsigned char data sin_TL0;
/* 與幅度相關 */
extern unsigned char data range_low, range_high;
extern float data proportion; /* 幅度與DAC量程之比 */
extern mdelay(unsigned int);
void main()
{
unsigned int count;
// unsigned char dec_bit;
//char rect_line1[] = "F DR:5/5#";
cur_signal = SIG_RECT;
freq = 500;
range_high = 0xff;
range_low = 0x00;
time_high = 1;
time_low = 1;
proportion = (float)(range_high - range_low) / 0xff;
count = (HZ * time_high) / (freq * 12 * (time_high + time_low)) * 1000000;
rect_high_TL0 = (unsigned char) count;
rect_high_TH0 = count >> 8;
count = (HZ * time_low) / (freq * 12 * (time_high + time_low)) * 1000000;
rect_low_TL0 = (unsigned char) count;
rect_low_TH0 = count >> 8;
count = (HZ / (12 * 256 * freq)) * 1000000;
sin_TL0 = (unsigned char) count;
sin_TH0 = count >> 8;
init_LCD1602();
//if( cur_signal == SIG_RECT)
// print_line(0, 10, "F DR:5/5#");
//else //cur_signal == SIG_SIN
// print_line(0, 10, "Z 0.5-5.0v");
enable_timer0();
enable_timer1();
printstr(0x0, 0xf, "SignalGenerator");
printstr(0x40, 0x4f, "program running!");
mdelay(1000);
LCD_write_cmd(0x01);
//print : program running
printstr(0xa, 0xf, "0500HZ");
while (1) {
if (cur_signal == SIG_RECT) {
printstr(0x0, 0x3, "F DR");
LCD_write_data(0, 4, time_high + 0x30);
LCD_write_data(0, 5, 'H');
LCD_write_data(0, 6, time_low + 0x30);
LCD_write_data(0, 7, 'L');
LCD_write_data(0, 8, ' ');
LCD_write_data(0, 9, ' ');
printstr(0x40, 0x4f, "SET DR: 5L 6H ");
} else {// 正弦波
LCD_write_data(0, 0, 'Z');
LCD_write_data(0, 1, ' ');
/* range_low / 50 + 0x30;將256個階分為25份,每份10,
* 對于Vref為5V的情況,10近似地代表0.2V
* 50近似代表1V, 所以這里的dec_bit表示幅度的整數部分
*/
LCD_write_data(0, 2, range_low / 50 + 0x30);
LCD_write_data(0, 3, '.');
LCD_write_data(0, 4, ((range_low / 5) % 10) + 0x30);
// (range_low / 5) % 10 + 0x30;range_low /5 表示0。1V的個數, %10 取個位數
LCD_write_data(0, 5, '-');
LCD_write_data(0, 6, range_high / 50 + 0x30);
LCD_write_data(0, 7, '.');
LCD_write_data(0, 8, (range_high / 5) % 10 + 0x30);
LCD_write_data(0, 9, 'V');
printstr(0x40, 0x4f, "mod:5 trg,6 crst");
//LCD_write_data(0, 4, (unsigned char)
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -