📄 sblcd.c
字号:
/* Code for driving the lcd on the HPA449 *//* HPA449 LCD config:- Segment 0 used for turning off unused segments. Normally off.- Antenna and alpha digit 7 tied to S1. Normally off.- Segs 2-11, 16-35 connected to elements.- Segs 12-15 switched between seg 0 or certain elements.- Segs 36-39 used for SPI only, not available for LCD.See also lcdmap.txt*/#include "sblcd.h"typedef struct seginfo { volatile char *loc; unsigned char mask;} seginfo;#include "sblcd_charset.c"void sblcd_seg_set(const seginfo *si, int on);// This LCD init turns all segments off.void sblcd_init(void){ int i; volatile char *volatile mp=&LCDM1; // (GH) init port functions and direction P4OUT = 0xc0; P4DIR = 0x00; P4SEL = 0xf8; P5OUT = 0xff; P5DIR = 0x00; P5SEL = 0xff; P6OUT = 0xff; P6DIR = 0x00; P6SEL = 0xff; //BTCTL=0010 1000 BTCTL=0x28; for (i=0;i<20;++i) { *mp=0; ++mp; } //lcdctl=1101 1101 LCDCTL=LCDP2|LCDP1|LCDP0|LCDMX1|LCDMX0|LCDSON|LCDON;}void sblcd_lg_showc(char c, int position){ volatile char *base; u16 digits; if (position<0) return; if (position>=SBLCD_LG_DIGITS) return; if (c<' ') return; if (c>='a'&&c<='z') c-=0x20; if (c>'Z') return; base=&LCDM17 - position*2; digits=starburst_segments[c-' ']; base[0] = digits; base[1] = (digits>>8)|(base[1]&0x90); }void SBLCD_SEG_SET(volatile char *loc, u8 mask, int on){ if (on) SBLCD_SEG_ON((volatile char *)loc,mask); else SBLCD_SEG_OFF((volatile char *)loc,mask);}void sblcd_seg_set(const seginfo *si, int on){ if (on) sblcd_seg_on(si); else sblcd_seg_off(si);}void sblcd_lg_dp_set(int ind, int on){ --ind; if (ind<0) return; if (ind>=6) return; if (ind>=SBLCD_LG_DIGITS) return; sblcd_seg_set(&(lgdptbl[ind]),on);}void sblcd_lg_colon_set(int ind, int on){ --ind; if (ind<0) return; if (ind>=5) return; if (ind>=SBLCD_LG_DIGITS) return; sblcd_seg_set(&(lgcolontbl[ind]),on);}void sblcd_lg_alldpcolonoff(void){ int i; for (i=1;i<7;++i) { sblcd_lg_colon_off(i); sblcd_lg_dp_off(i); }}/* Shows a string on the alpha portion of the HPA449's LCD */void sblcd_lg_showstr(char *c){ int i,blank=0; if (*c=='+') { sblcd_plus_on(); sblcd_minus_off(); c++; } else if (*c=='-') { sblcd_minus_on(); sblcd_plus_off(); c++; } else { sblcd_minus_off(); sblcd_plus_off(); } sblcd_lg_alldpcolonoff(); for (i=0;i<SBLCD_LG_DIGITS;++i) { if (!blank) if (!*c) blank=1; if (blank) sblcd_lg_showc(' ',i); else { if (*c=='.') { sblcd_lg_dp_on(i); sblcd_lg_colon_off(i); --i; } else if (*c==':') { sblcd_lg_colon_on(i); sblcd_lg_dp_off(i); --i; } else { sblcd_lg_showc(*c,i); } ++c; } }}#if SBLCD_HAVE_BARGRAPHvoid sblcd_bg_set(u16 segs){ int i; SBLCD_SEG_SET(SBLCD_SEG_BGR,segs&1); SBLCD_SEG_SET(SBLCD_SEG_BGL,segs&(1<<11)); for (i=9;i>=0;--i){ segs=segs>>1; sblcd_seg_set(&bargraphtbl[i],segs&1); }}void sblcd_bg_centre(int val){ val+=5; if (val<0) val=0; if (val>10) val=10; sblcd_bg_set(bgcentretbl[val]);}void sblcd_bg_onedot(int val){ if (val<0) val=0; if (val>11) val=11; sblcd_bg_set(bgonedottbl[val]);}void sblcd_bg_lr(int val){ if (val<0) val=0; if (val>10) val=10; sblcd_bg_set(bglrtbl[val]);}#endif// ---- small 7-seg display ----------------------------------------------unsigned char chrtosegs(char c){ if (c>='a'&&c<='z') c-=0x20; if (c>=' '&&c<='Z') return segtbl[c-' ']; if (c=='_') return 8; if (c=='|') return 6; if (c=='`') return 0x20; return 0;}// seg: 6=a, 5=b, ... , 0=gvoid sblcd_sm_seg_set(int seg, int pos, int on){ sblcd_seg_set(&(smsegtbl[pos*7+seg]),on);}void sblcd_sm_showsegs(u8 segs, int pos){ int i; for (i=0;i<7;++i) { sblcd_sm_seg_set(i,pos,segs&1); segs=segs>>1; }}void sblcd_sm_dp_set(int ind, int on){ --ind; if (ind<0) return; if (ind>=3) return; sblcd_seg_set(&(smdptbl[ind]),on);}void sblcd_sm_showc(char c, int pos){ u8 segs; if (pos<0) return; if (pos>3) return; segs=chrtosegs(c); sblcd_sm_showsegs(segs,pos);}void sblcd_sm_showstr(char *c){ int i,blank=0,colon=0; sblcd_sm_dp_off(1); sblcd_sm_dp_off(2); sblcd_sm_dp_off(3); for (i=0;i<4;++i) { if (!blank) { if (!*c) blank=1; } if (blank) sblcd_sm_showc(' ',i); else { if (*c==':') { if (i==2) colon=1; --i; } else if (*c=='.') { sblcd_sm_dp_on(i); if (i==2) colon=0; --i; } else { sblcd_sm_showc(*c,i); } ++c; } } sblcd_sm_colon_set(colon);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -